Skip to content

Instantly share code, notes, and snippets.

View Smakar20's full-sized avatar

Sohini Makar Smakar20

  • Rally Health Inc
  • San Francisco
View GitHub Profile
@Smakar20
Smakar20 / index.js
Created February 12, 2019 19:04
findAndReplacePattern.js created by smakar20 - https://repl.it/@smakar20/findAndReplacePatternjs
/*
You have a list of words and a pattern, and you want to know which words in words matches the pattern.
A word matches the pattern if there exists a permutation of letters p so that after replacing every letter x in the pattern with p(x), we get the desired word.
(Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.)
Return a list of the words in words that match the given pattern.
You may return the answer in any order.
@Smakar20
Smakar20 / index.js
Created February 10, 2019 04:32
addToArrayForm.js created by smakar20 - https://repl.it/@smakar20/addToArrayFormjs
/* For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].
Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.
Example 1:
Input: A = [1,2,0,0], K = 34
Output: [1,2,3,4]
@Smakar20
Smakar20 / index.js
Created February 10, 2019 04:31
TemptingForkedClosedsource-1 created by smakar20 - https://repl.it/@smakar20/TemptingForkedClosedsource-1
/* For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1].
Given the array-form A of a non-negative integer X, return the array-form of the integer X+K.
Example 1:
Input: A = [1,2,0,0], K = 34
Output: [1,2,3,4]
@Smakar20
Smakar20 / index.js
Created February 4, 2019 07:09
countOccurance.js created by smakar20 - https://repl.it/@smakar20/countOccurancejs
/* Count occurrences of a given number in a sorted array which has duplicates
[1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 8, 8, 12, 12, 12]
Given the number 2, we should return 5, since it appeared 5 times in the given array.
Complexity required - O(log(n))
*/
function findElement(arr, num){
@Smakar20
Smakar20 / index.js
Created January 23, 2019 19:14
capitalWords.js created by smakar20 - https://repl.it/@smakar20/capitalWordsjs
/* In the English language there are many grammatical uses of capitalisation, where the first letter of a word is rendered in uppercase. For example, proper nouns and the beginning of sentences. Therefore, when analysing a block of text, we may be interested in capitalised words.
In this Kata from an input string we want to return an array of the form [[Capitalised Words],number] where [Capitalised Words] is the array consisting of all words beginning with a single uppercase letter and number is its count (size).
The input string will only contain alphabetic chars and punctuation, no numerals or double whitespace for example.
So:
"This is an Input string Example." => [["This","Input","Example"],3]
"Do not count IBM Acronyms or other CAPITAL words." => [["Do","Acronyms"],2]
@Smakar20
Smakar20 / index.js
Created January 21, 2019 07:17
findLengthOfLCIS created by smakar20 - https://repl.it/@smakar20/findLengthOfLCIS
/* Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
Example 1:
Input: [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
Example 2:
Input: [2,2,2,2,2]
Output: 1
@Smakar20
Smakar20 / index.js
Created January 9, 2019 07:14
capitalize.js created by smakar20 - https://repl.it/@smakar20/capitalizejs
/*Given a string and an array of integers representing indices, capitalize all letters at the given indices.
For example:
capitalize("abcdef",[1,2,5]) = "aBCdeF"
capitalize("abcdef",[1,2,5,100]) = "aBCdeF". There is no index 100.
*/
function capitalize(s,arr){
var output = s.split('');
@Smakar20
Smakar20 / index.js
Created January 8, 2019 19:41
convertQueryToMap.js created by smakar20 - https://repl.it/@smakar20/convertQueryToMapjs
/*
We want to convert a URL query string into a nested object. The query string will contain parameters that may or may not have embedded dots ('.'), and these dots will be used to break up the properties into the nested object.
input: user.name.firstname=Bob&user.name.lastname=Smith&user.favoritecolor=Light%20Blue
output: {
'user': {
'name': {
'firstname': 'Bob',
'lastname': 'Smith'
},
@Smakar20
Smakar20 / details.txt
Created May 17, 2018 17:07
serialize and deserialize a tree created by smakar20 - https://repl.it/@smakar20/serialize-and-deserialize-a-tree
[{"id":"id-zcucxdjnql","detail":1},{"id":"id-bpxw5jnlwvj","detail":2},{"id":"id-ghu82cv1ae5","detail":3}]
/*Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
Given binary tree [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as: