repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/InsertDeleteGetRandomO1.java
leetcode/hash-table/InsertDeleteGetRandomO1.java
//Design a data structure that supports all following operations in average O(1) time. //insert(val): Inserts an item val to the set if not already present. //remove(val): Removes an item val from the set if present. //getRandom: Returns a random element from current set of elements. Each element must have the same pr...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/ValidAnagram.java
leetcode/hash-table/ValidAnagram.java
class ValidAnagram { public boolean isAnagram(String s, String t) { HashMap<Character, Integer> map = new HashMap<Character, Integer>(); for(char c: s.toCharArray()) { if(map.containsKey(c)) { map.put(c, map.get(c) + 1); } else { ma...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/MinimumWindowSubstring.java
leetcode/hash-table/MinimumWindowSubstring.java
// Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). // For example, // S = "ADOBECODEBANC" // T = "ABC" // Minimum window is "BANC". // Note: // If there is no such window in S that covers all characters in T, return the empty string "". // ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/BullsAndCows.java
leetcode/hash-table/BullsAndCows.java
//You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called "bulls")...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/FindAnagramMappings.java
leetcode/hash-table/FindAnagramMappings.java
//Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing the order of the elements in A. //We want to find an index mapping P, from A to B. A mapping P[i] = j means the ith element in A appears in B at index j. //These lists A and B may contain duplicates. If there are mul...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/ValidSudoku.java
leetcode/hash-table/ValidSudoku.java
//Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. (http://sudoku.com.au/TheRules.aspx) //The Sudoku board could be partially filled, where empty cells are filled with the character '.'. //A partially filled sudoku which is valid. //Note: //A valid Sudoku board (partially filled) is not necess...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/StrobogrammaticNumber.java
leetcode/hash-table/StrobogrammaticNumber.java
// A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). // Write a function to determine if a number is strobogrammatic. The number is represented as a string. // For example, the numbers "69", "88", and "818" are all strobogrammatic. public class Strobogrammatic...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/GroupAnagrams.java
leetcode/hash-table/GroupAnagrams.java
// Given an array of strings, group anagrams together. // For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], // Return: // [ // ["ate", "eat","tea"], // ["nat","tan"], // ["bat"] // ] // Note: All inputs will be in lower-case. public class GroupAnagrams { public List<List<String>> groupAnagra...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/ContainsDuplicate.java
leetcode/hash-table/ContainsDuplicate.java
//Given an array of integers, find if the array contains any duplicates. Your function should return //true if any value appears at least twice in the array, and it should return false if every element is distinct. class ContainsDuplicate { public boolean containsDuplicate(int[] nums) { HashMap<Integer, I...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/FindTheDifference.java
leetcode/hash-table/FindTheDifference.java
// Given two strings s and t which consist of only lowercase letters. // String t is generated by random shuffling string s and then add one more letter at a random position. // Find the letter that was added in t. // Example: // Input: // s = "abcd" // t = "abcde" // Output: // e // Explanation: // 'e' is the le...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/SparseMatrixMultiplication.java
leetcode/hash-table/SparseMatrixMultiplication.java
// Given two sparse matrices A and B, return the result of AB. // You may assume that A's column number is equal to B's row number. // Example: // A = [ // [ 1, 0, 0], // [-1, 0, 3] // ] // B = [ // [ 7, 0, 0 ], // [ 0, 0, 0 ], // [ 0, 0, 1 ] // ] // | 1 0 0 | | 7 0 0 | | 7 0 0 | // AB = | -1...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/BinaryTreeMaximumPathSum.java
leetcode/tree/BinaryTreeMaximumPathSum.java
// Given a binary tree, find the maximum path sum. // For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain at least one node and does not need to go through the root. // For example: // Given the below bi...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/InorderSuccessorInBST.java
leetcode/tree/InorderSuccessorInBST.java
// Given a binary search tree and a node in it, find the in-order successor of that node in the BST. // Note: If the given node has no in-order successor in the tree, return null. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * T...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/BinaryTreePaths.java
leetcode/tree/BinaryTreePaths.java
// Given a binary tree, return all root-to-leaf paths. // For example, given the following binary tree: // 1 // / \ // 2 3 // \ // 5 // All root-to-leaf paths are: // ["1->2->5", "1->3"] /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tr...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/TrimABinarySearchTree.java
leetcode/tree/TrimABinarySearchTree.java
//Given a binary search tree and the lowest and highest boundaries as L and R, trim the //tree so that all its elements lies in [L, R] (R >= L). You might need to change the root //of the tree, so the result should return the new root of the trimmed binary search tree. /** * Definition for a binary tree node. * pu...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/LowestCommonAncestorOfABinaryTree.java
leetcode/tree/LowestCommonAncestorOfABinaryTree.java
// Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. // According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of it...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/InvertBinaryTree.java
leetcode/tree/InvertBinaryTree.java
// Invert a binary tree. // 4 // / \ // 2 7 // / \ / \ // 1 3 6 9 // to // 4 // / \ // 7 2 // / \ / \ // 9 6 3 1 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { va...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/SumOfLeftLeaves.java
leetcode/tree/SumOfLeftLeaves.java
// Find the sum of all left leaves in a given binary tree. // Example: // 3 // / \ // 9 20 // / \ // 15 7 // There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. /** * Definition for a binary tree node. * public class TreeNode { * int val; * Tre...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/tree/ValidateBinarySearchTree.java
leetcode/tree/ValidateBinarySearchTree.java
// Given a binary tree, determine if it is a valid binary search tree (BST). // Assume a BST is defined as follows: // The left subtree of a node contains only nodes with keys less than the node's key. // The right subtree of a node contains only nodes with keys greater than the node's key. // Both the left and right...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/palantir/ContainsDuplicatesII.java
company/palantir/ContainsDuplicatesII.java
//Given an array of integers and an integer k, find out whether there are two distinct indices i and //j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most k. class ContainsDuplicatesII { public boolean containsNearbyDuplicate(int[] nums, int k) { HashMap<Integ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/palantir/ContainsDuplicate.java
company/palantir/ContainsDuplicate.java
//Given an array of integers, find if the array contains any duplicates. Your function should return //true if any value appears at least twice in the array, and it should return false if every element is distinct. class ContainsDuplicate { public boolean containsDuplicate(int[] nums) { HashMap<Integer, I...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/apple/ReverseWordsInAString.java
company/apple/ReverseWordsInAString.java
//Given an input string, reverse the string word by word. //For example, //Given s = "the sky is blue", //return "blue is sky the". public class ReverseWordsInAString { public String reverseWords(String s) { String[] words = s.trim().split("\\s+"); String result = ""; for(int i = words.leng...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/apple/ValidSudoku.java
company/apple/ValidSudoku.java
//Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. (http://sudoku.com.au/TheRules.aspx) //The Sudoku board could be partially filled, where empty cells are filled with the character '.'. //A partially filled sudoku which is valid. //Note: //A valid Sudoku board (partially filled) is not necess...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/yelp/ReverseWordsInAString.java
company/yelp/ReverseWordsInAString.java
//Given an input string, reverse the string word by word. //For example, //Given s = "the sky is blue", //return "blue is sky the". public class ReverseWordsInAString { public String reverseWords(String s) { String[] words = s.trim().split("\\s+"); String result = ""; for(int i = words.leng...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/yelp/InsertDeleteGetRandomO1.java
company/yelp/InsertDeleteGetRandomO1.java
//Design a data structure that supports all following operations in average O(1) time. //insert(val): Inserts an item val to the set if not already present. //remove(val): Removes an item val from the set if present. //getRandom: Returns a random element from current set of elements. Each element must have the same pr...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/adobe/AddDigits.java
company/adobe/AddDigits.java
//Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. //For example: //Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. //Follow up: //Could you do it without any loop/recursion in O(1) runtime? class AddDigits { p...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/adobe/MajorityElement.java
company/adobe/MajorityElement.java
//Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. //You may assume that the array is non-empty and the majority element always exist in the array. class MajorityElement { public int majorityElement(int[] nums) { if(nums.length =...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/ReverseLinkedList.java
company/twitter/ReverseLinkedList.java
// Reverse a singly linked list. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class ReverseLinkedList { public ListNode reverseList(ListNode head) { if(head == null) { return head; ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/MergeKSortedLists.java
company/twitter/MergeKSortedLists.java
// Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class MergeKSortedLists { public ListNode mergeKLists(...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/OneEditDistance.java
company/twitter/OneEditDistance.java
// Given two strings S and T, determine if they are both one edit distance apart. public class OneEditDistance { public boolean isOneEditDistance(String s, String t) { //iterate through the length of the smaller string for(int i = 0; i < Math.min(s.length(), t.length()); i++) { //if the...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/ImplementTrie.java
company/twitter/ImplementTrie.java
// Implement a trie with insert, search, and startsWith methods. // Note: // You may assume that all inputs are consist of lowercase letters a-z. // Your Trie object will be instantiated and called as such: // Trie trie = new Trie(); // trie.insert("somestring"); // trie.search("key"); class TrieNode { HashMap<C...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/MergeIntervals.java
company/twitter/MergeIntervals.java
// Given a collection of intervals, merge all overlapping intervals. // For example, // Given [1,3],[2,6],[8,10],[15,18], // return [1,6],[8,10],[15,18]. /** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/MultiplyStrings.java
company/twitter/MultiplyStrings.java
// Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. // Note: // The length of both num1 and num2 is < 110. // Both num1 and num2 contains only digits 0-9. // Both num1 and num2 does not contain any leading zero. // You must not use any built-in...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/RegularExpressionMatching.java
company/twitter/RegularExpressionMatching.java
// Implement regular expression matching with support for '.' and '*'. // '.' Matches any single character. // '*' Matches zero or more of the preceding element. // The matching should cover the entire input string (not partial). // The function prototype should be: // bool isMatch(const char *s, const char *p) // ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/InsertDeleteGetRandomO1.java
company/twitter/InsertDeleteGetRandomO1.java
//Design a data structure that supports all following operations in average O(1) time. //insert(val): Inserts an item val to the set if not already present. //remove(val): Removes an item val from the set if present. //getRandom: Returns a random element from current set of elements. Each element must have the same pr...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/ValidParentheses.java
company/twitter/ValidParentheses.java
// Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. // The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not. public class ValidParentheses { public boolean isValid(String s) { if(s.le...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/FlattenNestedListIterator.java
company/twitter/FlattenNestedListIterator.java
// Given a nested list of integers, implement an iterator to flatten it. // Each element is either an integer, or a list -- whose elements may also be integers or other lists. // Example 1: // Given the list [[1,1],2,[1,1]], // By calling next repeatedly until hasNext returns false, the order of elements returned by...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/TrappingRainWater.java
company/twitter/TrappingRainWater.java
// Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. // For example, // Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. public class TrappingRainWater { public int trap(int[] height) { int water = 0; ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/twitter/LowestCommonAncestorOfABinaryTree.java
company/twitter/LowestCommonAncestorOfABinaryTree.java
// Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. // According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of it...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/LinkedListCycle.java
company/microsoft/LinkedListCycle.java
//Given a linked list, determine if it has a cycle in it. //Follow up: //Can you solve it without using extra space? /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Sol...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/LongestIncreasingSubsequence.java
company/microsoft/LongestIncreasingSubsequence.java
//Given an unsorted array of integers, find the length of longest increasing subsequence. //For example, //Given [10, 9, 2, 5, 3, 7, 101, 18], //The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that there may be more than one LIS combination, it is only necessary for you to return ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/FirstUniqueCharacterInAString.java
company/microsoft/FirstUniqueCharacterInAString.java
//Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. // //Examples: // //s = "leetcode" //return 0. // //s = "loveleetcode", //return 2. //Note: You may assume the string contain only lowercase letters. class FirstUniqueCharacterInAString { public in...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/ReverseWordsInAString.java
company/microsoft/ReverseWordsInAString.java
//Given an input string, reverse the string word by word. //For example, //Given s = "the sky is blue", //return "blue is sky the". public class ReverseWordsInAString { public String reverseWords(String s) { String[] words = s.trim().split("\\s+"); String result = ""; for(int i = words.leng...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/AddDigits.java
company/microsoft/AddDigits.java
//Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. //For example: //Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. //Follow up: //Could you do it without any loop/recursion in O(1) runtime? class AddDigits { p...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/SpiralMatrix.java
company/microsoft/SpiralMatrix.java
//Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. // //Example 1: // //Input: //[ //[ 1, 2, 3 ], //[ 4, 5, 6 ], //[ 7, 8, 9 ] //] //Output: [1,2,3,6,9,8,7,4,5] //Example 2: // //Input: //[ //[1, 2, 3, 4], //[5, 6, 7, 8], //[9,10,11,12] //] //Output: [1,2...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/LongestPalindromicSubstring.java
company/microsoft/LongestPalindromicSubstring.java
//Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. //Example: //Input: "babad" //Output: "bab" //Note: "aba" is also a valid answer. //Example: //Input: "cbbd" //Output: "bb" class LongestPalindromicSubstring { public String longestPalindrome(St...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/Permutations.java
company/microsoft/Permutations.java
//Given a collection of distinct numbers, return all possible permutations. // //For example, //[1,2,3] have the following permutations: //[ //[1,2,3], //[1,3,2], //[2,1,3], //[2,3,1], //[3,1,2], //[3,2,1] //] class Permutations { public List<List<Integer>> permute(int[] nums) { LinkedList<List...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/microsoft/HouseRobberII.java
company/microsoft/HouseRobberII.java
//Note: This is an extension of House Robber. (security system is tripped if two ajacent houses are robbed) //After robbing those houses on that street, the thief has found himself a new place for his thievery so that //he will not get too much attention. This time, all houses at this place are arranged in a circle. T...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MergeKSortedLists.java
company/linkedin/MergeKSortedLists.java
// Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class MergeKSortedLists { public ListNode mergeKLists(...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/TwoSum.java
company/linkedin/TwoSum.java
// Given an array of integers, return indices of the two numbers such that they add up to a specific target. // You may assume that each input would have exactly one solution, and you may not use the same element twice. // Example: // Given nums = [2, 7, 11, 15], target = 9, // Because nums[0] + nums[1] = 2 + 7 = 9,...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/PalindromicSubstrings.java
company/linkedin/PalindromicSubstrings.java
//Given a string, your task is to count how many palindromic substrings in this string. //The substrings with different start indexes or end indexes are counted as different substrings //even they consist of same characters. //Example 1: //Input: "abc" //Output: 3 //Explanation: Three palindromic strings: "a", "b", "...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MergeIntervals.java
company/linkedin/MergeIntervals.java
// Given a collection of intervals, merge all overlapping intervals. // For example, // Given [1,3],[2,6],[8,10],[15,18], // return [1,6],[8,10],[15,18]. /** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/SymmetricTree.java
company/linkedin/SymmetricTree.java
// Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). // For example, this binary tree [1,2,2,3,4,4,3] is symmetric: // 1 // / \ // 2 2 // / \ / \ // 3 4 4 3 // But the following [1,2,2,null,3,null,3] is not: // 1 // / \ // 2 2 // \ \ // 3 ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/FindTheCelebrity.java
company/linkedin/FindTheCelebrity.java
// Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her but he/she does not know any of them. // Now you want to find out who the celebrity is or verify that there is not one. The ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MaximumDepthOfABinaryTree.java
company/linkedin/MaximumDepthOfABinaryTree.java
// Given a binary tree, find its maximum depth. // The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x)...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MaximumProductSubarray.java
company/linkedin/MaximumProductSubarray.java
// Find the contiguous subarray within an array (containing at least one number) which has the largest product. // For example, given the array [2,3,-2,4], // the contiguous subarray [2,3] has the largest product = 6. public class MaximumProductSubarray { public int maxProduct(int[] nums) { if(nums == nul...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/BinarySearchTreeIterator.java
company/linkedin/BinarySearchTreeIterator.java
// Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. // Calling next() will return the next smallest number in the BST. // Note: next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of the tree. /** * Def...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/ProductOfArrayExceptSelf.java
company/linkedin/ProductOfArrayExceptSelf.java
// Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. // Solve it without division and in O(n). // For example, given [1,2,3,4], return [24,12,8,6]. // Follow up: // Could you solve it with constant space comp...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MinimumWindowSubstring.java
company/linkedin/MinimumWindowSubstring.java
// Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). // For example, // S = "ADOBECODEBANC" // T = "ABC" // Minimum window is "BANC". // Note: // If there is no such window in S that covers all characters in T, return the empty string "". // ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/HouseRobber.java
company/linkedin/HouseRobber.java
// You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/InsertInterval.java
company/linkedin/InsertInterval.java
// Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). // You may assume that the intervals were initially sorted according to their start times. // Example 1: // Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9]. // Example 2: // Given [1,2],[...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/SparseMatrixMultiplication.java
company/linkedin/SparseMatrixMultiplication.java
// Given two sparse matrices A and B, return the result of AB. // You may assume that A's column number is equal to B's row number. // Example: // A = [ // [ 1, 0, 0], // [-1, 0, 3] // ] // B = [ // [ 7, 0, 0 ], // [ 0, 0, 0 ], // [ 0, 0, 1 ] // ] // | 1 0 0 | | 7 0 0 | | 7 0 0 | // AB = | -1...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/Permutations.java
company/linkedin/Permutations.java
//Given a collection of distinct numbers, return all possible permutations. // //For example, //[1,2,3] have the following permutations: //[ //[1,2,3], //[1,3,2], //[2,1,3], //[2,3,1], //[3,1,2], //[3,2,1] //] class Permutations { public List<List<Integer>> permute(int[] nums) { LinkedList<List...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/LowestCommonAncestorOfABinaryTree.java
company/linkedin/LowestCommonAncestorOfABinaryTree.java
// Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. // According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of it...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/PowerOfXToTheN.java
company/linkedin/PowerOfXToTheN.java
// Implement pow(x, n). public class PowerOfXToTheN { public double myPow(double x, int n) { if(n == 0) { return 1; } if(Double.isInfinite(x)) { return 0; } if(n < 0) { n = -n; x = 1 / x; } ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/MaximumSubarray.java
company/linkedin/MaximumSubarray.java
// Find the contiguous subarray within an array (containing at least one number) which has the largest sum. // For example, given the array [-2,1,-3,4,-1,2,1,-5,4], // the contiguous subarray [4,-1,2,1] has the largest sum = 6. public class MaximumSubarray { public int maxSubArray(int[] nums) { int[] dp =...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/PaintHouse.java
company/linkedin/PaintHouse.java
//There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. //The cost of painting each house with a certain color is different. You have to paint all the houses such //that no two adjacent houses have the same color. //The cost of painting each house with a certain col...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/BinaryTreeLevelOrderTraversal.java
company/linkedin/BinaryTreeLevelOrderTraversal.java
// Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). // For example: // Given binary tree [3,9,20,null,null,15,7], // 3 // / \ // 9 20 // / \ // 15 7 // return its level order traversal as: // [ // [3], // [9,20], // [15,7] /...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/linkedin/SearchInRotatedSortedArray.java
company/linkedin/SearchInRotatedSortedArray.java
// Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. // (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). // You are given a target value to search. If found in the array return its index, otherwise return -1. // You may assume no duplicate exists in the array. public cl...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/BinaryTreeVerticalOrderTraversal.java
company/facebook/BinaryTreeVerticalOrderTraversal.java
// Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). // If two nodes are in the same row and column, the order should be from left to right. // Examples: // Given binary tree [3,9,20,null,null,15,7], // 3 // /\ // / \ // 9 20 // /\...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/HammingDistance.java
company/facebook/HammingDistance.java
// The Hamming distance between two integers is the number of positions at which the corresponding bits are different. // Given two integers x and y, calculate the Hamming distance. // Note: // 0 ≤ x, y < 2^31. // Example: // Input: x = 1, y = 4 // Output: 2 // Explanation: // 1 (0 0 0 1) // 4 (0 1 0 0) // ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/ExpressionAddOperators.java
company/facebook/ExpressionAddOperators.java
// Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value. // Examples: // "123", 6 -> ["1+2+3", "1*2*3"] // "232", 8 -> ["2*3+2", "2+3*2"] // "105", 5 -> ["1*0+5","10-5"] // "00"...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/KthLargestElementInAnArray.java
company/facebook/KthLargestElementInAnArray.java
// Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. // For example, // Given [3,2,1,5,6,4] and k = 2, return 5. // Note: // You may assume k is always valid, 1 ≤ k ≤ array's length. public class KthLargestElementInAnArray {...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/CountAndSay.java
company/facebook/CountAndSay.java
// The count-and-say sequence is the sequence of integers beginning as follows: // 1, 11, 21, 1211, 111221, ... // 1 is read off as "one 1" or 11. // 11 is read off as "two 1s" or 21. // 21 is read off as "one 2, then one 1" or 1211. // Given an integer n, generate the nth sequence. // Note: The sequence of integers ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/NumberOfIslands.java
company/facebook/NumberOfIslands.java
// Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. // Example 1: // 11110 // 11010 // 11000 // 00000 // Answe...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/ReverseLinkedList.java
company/facebook/ReverseLinkedList.java
// Reverse a singly linked list. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class ReverseLinkedList { public ListNode reverseList(ListNode head) { if(head == null) { return head; ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/DecodeWays.java
company/facebook/DecodeWays.java
// A message containing letters from A-Z is being encoded to numbers using the following mapping: // 'A' -> 1 // 'B' -> 2 // ... // 'Z' -> 26 // Given an encoded message containing digits, determine the total number of ways to decode it. // For example, // Given encoded message "12", it could be decoded as "AB" (1 2...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MergeKSortedLists.java
company/facebook/MergeKSortedLists.java
// Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class MergeKSortedLists { public ListNode mergeKLists(...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/AddAndSearchWordDataStructureDesign.java
company/facebook/AddAndSearchWordDataStructureDesign.java
// Design a data structure that supports the following two operations: // void addWord(word) // bool search(word) // search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter. // For example: // addWord("bad") // addWord("dad") /...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/EncodeAndDecodeTinyURL.java
company/facebook/EncodeAndDecodeTinyURL.java
//TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl //and it returns a short URL such as http://tinyurl.com/4e9iAk. // //Design the encode and decode methods for the TinyURL service. There is no restriction on how your //encode/decode algorithm should work....
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/OneEditDistance.java
company/facebook/OneEditDistance.java
// Given two strings S and T, determine if they are both one edit distance apart. public class OneEditDistance { public boolean isOneEditDistance(String s, String t) { //iterate through the length of the smaller string for(int i = 0; i < Math.min(s.length(), t.length()); i++) { //if the...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/ImplementTrie.java
company/facebook/ImplementTrie.java
// Implement a trie with insert, search, and startsWith methods. // Note: // You may assume that all inputs are consist of lowercase letters a-z. // Your Trie object will be instantiated and called as such: // Trie trie = new Trie(); // trie.insert("somestring"); // trie.search("key"); class TrieNode { HashMap<C...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MoveZeros.java
company/facebook/MoveZeros.java
// Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. // For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0]. // Note: // You must do this in-place without making a copy of the a...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/TwoSum.java
company/facebook/TwoSum.java
// Given an array of integers, return indices of the two numbers such that they add up to a specific target. // You may assume that each input would have exactly one solution, and you may not use the same element twice. // Example: // Given nums = [2, 7, 11, 15], target = 9, // Because nums[0] + nums[1] = 2 + 7 = 9,...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MinimumSizeSubarraySum.java
company/facebook/MinimumSizeSubarraySum.java
// Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead. // For example, given the array [2,3,1,2,4,3] and s = 7, // the subarray [4,3] has the minimal length under the problem constraint. public cla...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/PalindromicSubstrings.java
company/facebook/PalindromicSubstrings.java
//Given a string, your task is to count how many palindromic substrings in this string. //The substrings with different start indexes or end indexes are counted as different substrings //even they consist of same characters. //Example 1: //Input: "abc" //Output: 3 //Explanation: Three palindromic strings: "a", "b", "...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/CloneGraph.java
company/facebook/CloneGraph.java
// Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. // OJ's undirected graph serialization: // Nodes are labeled uniquely. // We use # as a separator for each node, and , as a separator for node label and each neighbor of the node. // As an example, consider the serializ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/InorderSuccessorInBST.java
company/facebook/InorderSuccessorInBST.java
// Given a binary search tree and a node in it, find the in-order successor of that node in the BST. // Note: If the given node has no in-order successor in the tree, return null. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * T...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/IntegerToEnglishWords.java
company/facebook/IntegerToEnglishWords.java
// Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. // For example, // 123 -> "One Hundred Twenty Three" // 12345 -> "Twelve Thousand Three Hundred Forty Five" // 1234567 -> "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven" p...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MergeIntervals.java
company/facebook/MergeIntervals.java
// Given a collection of intervals, merge all overlapping intervals. // For example, // Given [1,3],[2,6],[8,10],[15,18], // return [1,6],[8,10],[15,18]. /** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MergeSortedArray.java
company/facebook/MergeSortedArray.java
// Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. // Note: // You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively. public...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/3Sum.java
company/facebook/3Sum.java
// Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. // Note: The solution set must not contain duplicate triplets. // For example, given array S = [-1, 0, 1, 2, -1, -4], // A solution set is: // [ // [-1, 0, ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/LetterCombinationsOfAPhoneNumber.java
company/facebook/LetterCombinationsOfAPhoneNumber.java
// Given a digit string, return all possible letter combinations that the number could represent. // A mapping of digit to letters (just like on the telephone buttons) is given below. // 2 - abc // 3 - def // 4 - ghi // 5 - jkl // 6 - mno // 7 - pqrs // 8 - tuv // 9 - wxyz // Input:Digit string "23" // Output: ["ad"...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MultiplyStrings.java
company/facebook/MultiplyStrings.java
// Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. // Note: // The length of both num1 and num2 is < 110. // Both num1 and num2 contains only digits 0-9. // Both num1 and num2 does not contain any leading zero. // You must not use any built-in...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/FindTheCelebrity.java
company/facebook/FindTheCelebrity.java
// Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her but he/she does not know any of them. // Now you want to find out who the celebrity is or verify that there is not one. The ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/BestTimeToBuyAndSellStock.java
company/facebook/BestTimeToBuyAndSellStock.java
// Say you have an array for which the ith element is the price of a given stock on day i. // If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. // Example 1: // Input: [7, 1, 5, 3, 6, 4] // Output: 5 // max. d...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MinStack.java
company/facebook/MinStack.java
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack(); * obj.push(x); * obj.pop(); * int param_3 = obj.top(); * int param_4 = obj.getMin(); */ class MinStack { class Node { int data; int min; Node next; public Node(int dat...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/RegularExpressionMatching.java
company/facebook/RegularExpressionMatching.java
// Implement regular expression matching with support for '.' and '*'. // '.' Matches any single character. // '*' Matches zero or more of the preceding element. // The matching should cover the entire input string (not partial). // The function prototype should be: // bool isMatch(const char *s, const char *p) // ...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/MaximumSizeSubarraySumEqualsK.java
company/facebook/MaximumSizeSubarraySumEqualsK.java
// Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead. // Note: // The sum of the entire nums array is guaranteed to fit within the 32-bit signed integer range. // Example 1: // Given nums = [1, -1, 5, -2, 3], k = 3, // return 4. (becau...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/company/facebook/InsertDeleteGetRandomO1.java
company/facebook/InsertDeleteGetRandomO1.java
//Design a data structure that supports all following operations in average O(1) time. //insert(val): Inserts an item val to the set if not already present. //remove(val): Removes an item val from the set if present. //getRandom: Returns a random element from current set of elements. Each element must have the same pr...
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false