This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
NewerOlder