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.html
Created March 21, 2019 03:08
displayDeckOfCards created by smakar20 - https://repl.it/@smakar20/displayDeckOfCards
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="displayDiv"></div>
@Smakar20
Smakar20 / index.js
Created February 15, 2019 18:35
getMostRepeated.js created by smakar20 - https://repl.it/@smakar20/getMostRepeatedjs
/*
array = [2, 1, 2, 1, 1, 3, 4, 3, 5]
f(array, k) = Return the Top K most repeating integers in the array
f(array, 1) = [1]
f(array, 2) = [1, 2] OR [1, 3]
f(array, 3) = [1, 2, 3] OR [1, 3, 2]
*/
function getMostRepeated(arr, k){
if (arr.length === 0 || k === 0) return 0;
@Smakar20
Smakar20 / index.js
Created February 15, 2019 18:25
implementTrie.js created by smakar20 - https://repl.it/@smakar20/implementTriejs
/*
Implement a trie with insert, search, and startsWith methods.
Example:
Trie trie = new Trie();
trie.insert("apple");
trie.search("apple"); // returns true
trie.search("app"); // returns false
@Smakar20
Smakar20 / index.js
Created February 14, 2019 04:36
addTwoNumbersII.js created by smakar20 - https://repl.it/@smakar20/addTwoNumbersIIjs
/**
* Definition for singly-linked list.*/
function ListNode(val) {
this.val = val;
this.next = null;
}
/**
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
@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