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 |
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 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(''); |
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
/* | |
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' | |
}, |
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
[{"id":"id-zcucxdjnql","detail":1},{"id":"id-bpxw5jnlwvj","detail":2},{"id":"id-ghu82cv1ae5","detail":3}] |
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 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: |