Skip to content

Instantly share code, notes, and snippets.

View rfaisal's full-sized avatar

Faisal Rahman rfaisal

  • Facebook
  • Vancouver, BC
View GitHub Profile
class Solution(object):
def countSmaller(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
idx = [0 for x in range(len(nums))]
for i in range(len(nums)):
idx[i] = (nums[i], i)
@rfaisal
rfaisal / Codeforces6C.java
Last active January 10, 2020 10:53
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the pla…
/**
* Problem Link: http://codeforces.com/problemset/problem/6/C
* Alice = getDivideIndex(..)+1;
* Bob = arrayLength - Alice;
*/
public class Codeforces6C {
private static int getDivideIndexRec(int[] arr, int i, int j, boolean isLeft){
if(i==j){
if(isLeft) return i-1;
else return i;
@rfaisal
rfaisal / StringSimilarity.java
Last active November 11, 2019 19:43
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings “abc” and “abd” is 2, while the similarity of strings “aaa” and “aaab” is 3. Calculate the sum of similarities of a string S with each of it’s suffixes.
public class StringSimilarity {
public static int calculate(String s){
char[]arr=s.toCharArray();
int length=arr.length;
int count=length;
for(int i=1;i<length;i++){
int len=length-i;
int j=0;
for(;j<len;j++)
if(arr[j]!=arr[j+i]){
var a = Rx.Observable.create(function(observer) {
setInterval(function() {
var curA = Math.floor((Math.random() * 100) + 1);
console.log("Current value of a " + curA);
observer.onNext(curA);
}, 3000);
});
var b = 0;
a.subscribe(function(val) {
b=val+1;
var a = 10;
var b = a + 1;
a = 20;
console.log(b);
[EnableCors(origins: "*", headers: "*", methods: "*")]
// [Authorize]
public class ValuesController : ApiController
{
private static List<string> values = new List<string>();
// GET api/values
public IEnumerable<string> Get()
{
return values;
}
[RequireHttps]
[EnableCors(origins: "*", headers: "*", methods: "*")]
[Authorize]
[RoutePrefix("api/Account")]
public class AccountController : ApiController {/*class definition*/}
OAuthOptions = new OAuthAuthorizationServerOptions
{
//other stuff
TokenEndpointPath = new PathString("/Token")
// AllowInsecureHttp = true
};
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", 'Bearer ' + _access_token);
},