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 / MvdI-2.js
Created October 26, 2017 21:22
null created by smakar20 - https://repl.it/MvdI/2
/*Have the function MatchingCharacters(str) take the str parameter being passed and determine the largest number of unique characters that exists between a pair of matching letters anywhere in the string. For example: if str is "ahyjakh" then there are only two pairs of matching letters, the two a's and the two h's. Between the pair of a's there are 3 unique characters: h, y, and j. Between the h's there are 4 unique characters: y, j, a, and k. So for this example your program should return 4.
Another example: if str is "ghececgkaem" then your program should return 5 because the most unique characters exists within the farthest pair of e characters. The input string may not contain any character pairs, and in that case your program should just return 0. The input will only consist of lowercase alphabetic characters. */
(function MatchingCharacters(str) {
var count = 0
for(var i = 0; i < str.length; i++){
var charObj = {}
var lastIdx = str.lastIndexOf(str[i])
if(i == lastIdx) con
@Smakar20
Smakar20 / Kovh-0.js
Created September 7, 2017 22:56
null created by smakar20 - https://repl.it/Kovh/0
/*Have the function WildcardCharacters(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, and {N} which is optional. The plus (+) character represents a single alphabetic character, the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many characters should appear in the sequence where N will be at least 1. Your goal is to determine if the second string exactly matches the pattern of the first string in the input.
For example: if str is "++*{5} gheeeee" then the second string in this case does match the pattern, so your program should return the string true. If the second string does not match the pattern your program should return the string false.*/
function WildcardCharacters(str) {
// code goes here
let strArr= str.split(' ')
let specChar = strArr[0]
let charStr = strArr[1].split('')
@Smakar20
Smakar20 / LyOf-1.js
Created October 2, 2017 22:29
null created by smakar20 - https://repl.it/LyOf/1
/*Have the function LargestFour(arr) take the array of integers stored in arr, and find the four largest elements and return their sum. For example: if arr is [4, 5, -2, 3, 1, 2, 6, 6] then the four largest elements in this array are 6, 6, 4, and 5 and the total sum of these numbers is 21, so your program should return 21. If there are less than four numbers in the array your program should return the sum of all the numbers in the array. */
(function LargestFour(arr) {
if(arr.length <= 4) return arr.reduce((a,b)=>{ return a+b},0)
var sorted = arr.sort((a,b)=>{return a-b})
return LargestFour(sorted.slice(-4))
}([4, 5, -2, 3, 1, 2, 6, 6]))
@Smakar20
Smakar20 / MsMo-0.js
Created October 19, 2017 03:27
null created by smakar20 - https://repl.it/MsMo/0
/*
Have the function StockPicker(arr) take the array of numbers stored in arr which will contain integers that represent the amount in dollars that a single stock is worth, and return the maximum profit that could have been made by buying stock on day x and selling stock on day y where y > x. For example: if arr is [44, 30, 24, 32, 35, 30, 40, 38, 15] then your program should return 16 because at index 2 the stock was worth $24 and at index 6 the stock was then worth $40, so if you bought the stock at 24 and sold it at 40, you would have made a profit of $16, which is the maximum profit that could have been made with this list of stock prices.
If there is not profit that could have been made with the stock prices, then your program should return -1. For example: arr is [10, 9, 8, 2] then your program should return -1.
*/
(function test(arr){
var temp = -1
for(i = 0; i < arr.length-1; i++){
for(j = i+1; j < arr.length; j++){
if(temp < arr[j] - arr[i]) temp = arr[j]-arr[i]
@Smakar20
Smakar20 / LK9y-0.js
Created September 15, 2017 22:55
null created by smakar20 - https://repl.it/LK9y/0
/*Have the function TriangleRow(num) take num which will be a positive integer representing some row from Pascal's triangle. Pascal's triangle starts with a [1] at the 0th row of the triangle. Then the first row is [1, 1] and the second row is [1, 2, 1]. The next row begins with 1 and ends with 1, and the inside of the row is determined by adding the k-1 and kth elements from the previous row. The next row in the triangle would then be [1, 3, 3, 1], and so on. The input will be some positive integer and your goal is to return the sum of that row. For example: if num is 4 then your program should return the sum of 1 + 4 + 6 + 4 + 1 which is 16. */
(function TriangleRow(num) {
var arr = []
for(var i = 0; i <= num; i++){
if(i == 0){
arr.push([1])
continue
}
var temp = arr[arr.length - 1]
@Smakar20
Smakar20 / M0Jm-1.js
Created October 10, 2017 22:06
null created by smakar20 - https://repl.it/M0Jm/1
/*Have the function BlackjackHighest(strArr) take the strArr parameter being passed which will be an array of numbers and letters representing blackjack cards. Numbers in the array will be written out. So for example strArr may be ["two","three","ace","king"]. The full list of possibilities for strArr is: two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace. Your program should output below, above, or blackjack signifying if you have blackjack (numbers add up to 21) or not and the highest card in your hand in relation to whether or not you have blackjack. If the array contains an ace but your hand will go above 21, you must count the ace as a 1. You must always try and stay below the 21 mark. So using the array mentioned above, the output should be below king. The ace is counted as a 1 in this example because if it wasn't you would be above the 21 mark. Another example would be if strArr was ["four","ten","king"], the output here should be above king. If you have a tie between a ten an
@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.