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/bit-manipulation/MaximumProductOfWordLengths.java | leetcode/bit-manipulation/MaximumProductOfWordLengths.java | // Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0.
// Example 1:
// Given ["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]
//... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/bit-manipulation/NumberOfOneBits.java | leetcode/bit-manipulation/NumberOfOneBits.java | // Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
// For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.
public class NumberOfOneBits {
// you need to treat ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/bit-manipulation/PowerOfTwo.java | leetcode/bit-manipulation/PowerOfTwo.java | //Given an integer, write a function to determine if it is a power of two.
//
//Example 1:
//
//Input: 1
//Output: true
//Example 2:
//
//Input: 16
//Output: true
//Example 3:
//
//Input: 218
//Output: false
class PowerOfTwo {
public boolean isPowerOfTwo(int n) {
long i = 1;
while(i < n) {
... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/bit-manipulation/SumOfTwoInteger.java | leetcode/bit-manipulation/SumOfTwoInteger.java | // Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
// Example:
// Given a = 1 and b = 2, return 3.
public class SumOfTwoIntegers {
public int getSum(int a, int b) {
if(a == 0) {
return b;
}
if(b == 0) {
return a;
... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/bit-manipulation/BinaryWatch.java | leetcode/bit-manipulation/BinaryWatch.java | // A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).
// Each LED represents a zero or one, with the least significant bit on the right.
// For example, the above binary watch reads "3:25".
// Given a non-negative integer n which represen... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/bit-manipulation/Utf8Validation.java | leetcode/bit-manipulation/Utf8Validation.java | // A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:
// For 1-byte character, the first bit is a 0, followed by its unicode code.
// For n-bytes character, the first n-bits are all one's, the n+1 bit is 0, followed by n-1 bytes with most significant 2 bits being 10.
// This is how th... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/divide-and-conquer/ExpressionAddOperators.java | leetcode/divide-and-conquer/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/leetcode/divide-and-conquer/KthLargestElementInAnArray.java | leetcode/divide-and-conquer/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/leetcode/stack/DailyTemperatures.java | leetcode/stack/DailyTemperatures.java | //Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
//
//For example, given the list temperatures = [73, 74, 75, 71, 69, 72, 76, 73], your out... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/stack/MinStack.java | leetcode/stack/MinStack.java | //Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
//push(x) -- Push element x onto stack.
//pop() -- Removes the element on top of the stack.
//top() -- Get the top element.
//getMin() -- Retrieve the minimum element in the stack.
/**
* Your MinStack object will be in... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/stack/BinarySearchTreeIterator.java | leetcode/stack/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/leetcode/stack/DecodeString.java | leetcode/stack/DecodeString.java | // Given an encoded string, return it's decoded string.
// The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
// You may assume that the input string is always valid; No extra white spaces,... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/stack/FlattenNestedListIterator.java | leetcode/stack/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/leetcode/stack/TrappingRainWater.java | leetcode/stack/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/leetcode/stack/ExclusiveTimeOfFunctions.java | leetcode/stack/ExclusiveTimeOfFunctions.java | //Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find the exclusive time of these functions.
//Each function has a unique id, start from 0 to n-1. A function may be called recursively or by another function.
//A log is a string has this format : function_id:start_or_en... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/queue/MovingAverageFromDataStream.java | leetcode/queue/MovingAverageFromDataStream.java | // Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.
// For example,
// MovingAverage m = new MovingAverage(3);
// m.next(1) = 1
// m.next(10) = (1 + 10) / 2
// m.next(3) = (1 + 10 + 3) / 3
// m.next(5) = (10 + 3 + 5) / 3
/**
* Your MovingAverage object... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/brainteaser/BulbSwitcher.java | leetcode/brainteaser/BulbSwitcher.java | //There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb. Find how ma... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/two-pointers/LinkedListCycle.java | leetcode/two-pointers/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/leetcode/two-pointers/MoveZeros.java | leetcode/two-pointers/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/leetcode/two-pointers/MinimumSizeSubarraySum.java | leetcode/two-pointers/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/leetcode/two-pointers/MergeSortedArray.java | leetcode/two-pointers/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/leetcode/two-pointers/3Sum.java | leetcode/two-pointers/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/leetcode/two-pointers/3SumSmaller.java | leetcode/two-pointers/3SumSmaller.java | // Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
// For example, given nums = [-2, 0, 1, 3], and target = 2.
// Return 2. Because there are two triplets which sums are less than 2:
// ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/two-pointers/RemoveElement.java | leetcode/two-pointers/RemoveElement.java | //Given an array and a value, remove all instances of that value in-place and return the new length.
//Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
//The order of elements can be changed. It doesn't matter what you leave beyond the new len... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/two-pointers/RemoveDuplicatesFromSortedArray.java | leetcode/two-pointers/RemoveDuplicatesFromSortedArray.java | // Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
// Do not allocate extra space for another array, you must do this in place with constant memory.
// For example,
// Given input array nums = [1,1,2],
// Your function should return length = 2, ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/two-pointers/SortColors.java | leetcode/two-pointers/SortColors.java | // Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
// Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
// Note:
// You are not suppose to use th... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/two-pointers/ReverseString.java | leetcode/two-pointers/ReverseString.java | // Write a function that takes a string as input and returns the string reversed.
// Example:
// Given s = "hello", return "olleh".
public class ReverseString {
public String reverseString(String s) {
if(s == null || s.length() == 1 || s.length() == 0) {
return s;
}
ch... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/depth-first-search/NumberOfIslands.java | leetcode/depth-first-search/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/leetcode/depth-first-search/BattleshipsInABoard.java | leetcode/depth-first-search/BattleshipsInABoard.java | // Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:
// You receive a valid board, made of only battleships or empty slots.
// Battleships can only be placed horizontally or vertically. In other... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/depth-first-search/MaximumDepthOfABinaryTree.java | leetcode/depth-first-search/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/leetcode/depth-first-search/BalancedBinaryTree.java | leetcode/depth-first-search/BalancedBinaryTree.java | // Given a binary tree, determine if it is height-balanced.
// For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeN... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/depth-first-search/SameTree.java | leetcode/depth-first-search/SameTree.java | // Given two binary trees, write a function to check if they are equal or not.
// Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/depth-first-search/ConvertSortedArrayToBinarySearchTree.java | leetcode/depth-first-search/ConvertSortedArrayToBinarySearchTree.java | // Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class ConvertSortedArrayToBinarySear... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/depth-first-search/PopulatingNextRightPointersInEachNode.java | leetcode/depth-first-search/PopulatingNextRightPointersInEachNode.java | // Given a binary tree
// struct TreeLinkNode {
// TreeLinkNode *left;
// TreeLinkNode *right;
// TreeLinkNode *next;
// }
// Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
// Initially, all next pointers ar... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MinCostClimbingStairs.java | leetcode/array/MinCostClimbingStairs.java | //On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
//
//Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
//
//Example 1:
//Input:... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/PlusOne.java | leetcode/array/PlusOne.java | //Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
//
//The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
//
//You may assume the integer does not contain any leading zero, except th... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MergeIntervals.java | leetcode/array/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/leetcode/array/UniquePaths.java | leetcode/array/UniquePaths.java | //A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
//
//The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
//
//How many possible unique paths are ther... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/ContainsDuplicatesII.java | leetcode/array/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/leetcode/array/FindTheCelebrity.java | leetcode/array/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/leetcode/array/BestTimeToBuyAndSellStock.java | leetcode/array/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/leetcode/array/SpiralMatrixII.java | leetcode/array/SpiralMatrixII.java | // Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
// For example,
// Given n = 3,
// You should return the following matrix:
// [
// [ 1, 2, 3 ],
// [ 8, 9, 4 ],
// [ 7, 6, 5 ]
// ]
public class SpiralMatrix {
public int[][] generateMatrix(int n) {
int[... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/RemoveElement.java | leetcode/array/RemoveElement.java | //Given an array and a value, remove all instances of that value in-place and return the new length.
//Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
//The order of elements can be changed. It doesn't matter what you leave beyond the new len... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MaximumProductSubarray.java | leetcode/array/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/leetcode/array/SpiralMatrix.java | leetcode/array/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/leetcode/array/InsertDeleteGetRandomO1.java | leetcode/array/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/array/GameOfLife.java | leetcode/array/GameOfLife.java | // According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."
// Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight neighbors (horizon... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MissingRanges.java | leetcode/array/MissingRanges.java | // Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], return its missing ranges.
// For example, given [0, 1, 3, 50, 75], lower = 0 and upper = 99, return ["2", "4->49", "51->74", "76->99"].
public class MissingRanges {
public List<String> findMissingRanges(int[] n... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/WiggleSort.java | leetcode/array/WiggleSort.java | // Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] <= nums[3]....
// For example, given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].
public class WiggleSort {
public void wiggleSort(int[] nums) {
for(int i = 1; i < nums.length; i++) {
... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/ProductofArrayExceptSelf.java | leetcode/array/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/leetcode/array/Subsets.java | leetcode/array/Subsets.java | // Given a set of distinct integers, nums, return all possible subsets.
// Note: The solution set must not contain duplicate subsets.
// For example,
// If nums = [1,2,3], a solution is:
// [
// [3],
// [1],
// [2],
// [1,2,3],
// [1,3],
// [2,3],
// [1,2],
// []
// ]
public class Subsets {
publ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/FindAllNumbersDisappearedInAnArray.java | leetcode/array/FindAllNumbersDisappearedInAnArray.java | //Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
//
//Find all the elements of [1, n] inclusive that do not appear in this array.
//
//Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/SubsetsII.java | leetcode/array/SubsetsII.java | // Given a collection of integers that might contain duplicates, nums, return all possible subsets.
// Note: The solution set must not contain duplicate subsets.
// For example,
// If nums = [1,2,2], a solution is:
// [
// [2],
// [1],
// [1,2,2],
// [2,2],
// [1,2],
// []
// ]
public class SubsetsI... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/InsertInterval.java | leetcode/array/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/leetcode/array/MajorityElement.java | leetcode/array/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/leetcode/array/LongestConsecutiveSequence.java | leetcode/array/LongestConsecutiveSequence.java | // Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
// For example,
// Given [100, 4, 200, 1, 3, 2],
// The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.
// Your algorithm should run in O(n) complexity.
class LongestConsecutiveSequence ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MaximumSubarray.java | leetcode/array/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 Solution {
public int maxSubArray(int[] nums) {
int[] d... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/MinimumPathSum.java | leetcode/array/MinimumPathSum.java | //Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right
//which minimizes the sum of all numbers along its path.
//Note: You can only move either down or right at any point in time.
//Example 1:
//[[1,3,1],
//[1,5,1],
//[4,2,1]]
//Given the above grid map, return 7. Because t... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/IncreasingTripletSubsequence.java | leetcode/array/IncreasingTripletSubsequence.java | // Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
// Formally the function should:
// Return true if there exists i, j, k
// such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.
// Your algorithm should run in O(n) time complexity an... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/WordSearch.java | leetcode/array/WordSearch.java | // Given a 2D board and a word, find if the word exists in the grid.
// The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
// For example,
// Given board =
// [
// ['A'... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/SearchInRotatedSortedArray.java | leetcode/array/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/leetcode/array/SummaryRanges.java | leetcode/array/SummaryRanges.java | // Given a sorted integer array without duplicates, return the summary of its ranges.
// For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].
public class SummaryRanges {
public List<String> summaryRanges(int[] nums) {
List<String> result = new ArrayList();
if(nums.length == 1) {... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/array/RotateImage.java | leetcode/array/RotateImage.java | // You are given an n x n 2D matrix representing an image.
// Rotate the image by 90 degrees (clockwise).
// Follow up:
// Could you do this in-place?
public class RotateImage {
public void rotate(int[][] matrix) {
for(int i = 0; i < matrix.length; i++) {
for(int j = 0; j < i; j++) {
... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/greedy/BestTimeToBuyAndSellStockII.java | leetcode/greedy/BestTimeToBuyAndSellStockII.java | //Say you have an array for which the ith element is the price of a given stock on day i.
//Design an algorithm to find the maximum profit. You may complete as many transactions as you
//like (ie, buy one and sell one share of the stock multiple times). However, you may not engage
//in multiple transactions at the sa... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/LongestIncreasingSubsequence.java | leetcode/dynamic-programming/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/leetcode/dynamic-programming/EditDistance.java | leetcode/dynamic-programming/EditDistance.java | // Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)
// You have the following 3 operations permitted on a word:
// a) Insert a character
// b) Delete a character
// c) Replace a character
public class EditDistance {
publi... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/MinCostClimbingStairs.java | leetcode/dynamic-programming/MinCostClimbingStairs.java | //On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
//
//Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
//
//Example 1:
//Input:... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/PaintFence.java | leetcode/dynamic-programming/PaintFence.java | // There is a fence with n posts, each post can be painted with one of the k colors.
// You have to paint all the posts such that no more than two adjacent fence posts have the same color.
// Return the total number of ways you can paint the fence.
// Note:
// n and k are non-negative integers.
public class PaintFe... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/PalindromicSubstrings.java | leetcode/dynamic-programming/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/leetcode/dynamic-programming/CountingBits.java | leetcode/dynamic-programming/CountingBits.java | // Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.
// Example:
// For num = 5 you should return [0,1,1,2,1,2].
// Follow up:
// It is very easy to come up with a solution with run time O(n*si... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/UniquePaths.java | leetcode/dynamic-programming/UniquePaths.java | //A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
//
//The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
//
//How many possible unique paths are ther... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/SentenceScreenFitting.java | leetcode/dynamic-programming/SentenceScreenFitting.java | // Given a rows x cols screen and a sentence represented by a list of non-empty words, find how many times the given sentence can be fitted on the screen.
// Note:
// A word cannot be split into two lines.
// The order of words in the sentence must remain unchanged.
// Two consecutive words in a line must ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/RegularExpressionMatching.java | leetcode/dynamic-programming/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/leetcode/dynamic-programming/CoinChange.java | leetcode/dynamic-programming/CoinChange.java | //You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
//Example 1:
//coins = [1, 2, 5], amount = 11
//return ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/UniqueBinarySearchTrees.java | leetcode/dynamic-programming/UniqueBinarySearchTrees.java | // Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
// For example,
// Given n = 3, there are a total of 5 unique BST's.
// 1 3 3 2 1
// \ / / / \ \
// 3 2 1 1 3 2
// / / \ ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/BombEnemy.java | leetcode/dynamic-programming/BombEnemy.java | // Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return the maximum enemies you can kill using one bomb.
// The bomb kills all the enemies in the same row and column from the planted point until it hits the wall since the wall is too strong to be destroyed.
// Note that ... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/HouseRobber.java | leetcode/dynamic-programming/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/leetcode/dynamic-programming/WordBreak.java | leetcode/dynamic-programming/WordBreak.java | // Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may assume the dictionary does not contain duplicate words.
// For example, given
// s = "leetcode",
// dict = ["leet", "cod... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/PaintHouseII.java | leetcode/dynamic-programming/PaintHouseII.java | // There are a row of n houses, each house can be painted with one of the k colors. 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 color is represented by a n... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/CombinationSumIV.java | leetcode/dynamic-programming/CombinationSumIV.java | // Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.
// Example:
// nums = [1, 2, 3]
// target = 4
// The possible combination ways are:
// (1, 1, 1, 1)
// (1, 1, 2)
// (1, 2, 1)
// (1, 3)
// (2, 1, 1)
// (2, 2)
// (... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/PaintHouse.java | leetcode/dynamic-programming/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/leetcode/dynamic-programming/MinimumPathSum.java | leetcode/dynamic-programming/MinimumPathSum.java | //Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right
//which minimizes the sum of all numbers along its path.
//Note: You can only move either down or right at any point in time.
//Example 1:
//[[1,3,1],
//[1,5,1],
//[4,2,1]]
//Given the above grid map, return 7. Because t... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/ClimbingStairs.java | leetcode/dynamic-programming/ClimbingStairs.java | // You are climbing a stair case. It takes n steps to reach to the top.
// Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
// Note: Given n will be a positive integer.
public class ClimbingStairs {
public int climbStairs(int n) {
int[] dp = new int[n + 1];... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/dynamic-programming/HouseRobberII.java | leetcode/dynamic-programming/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/leetcode/design/MinStack.java | leetcode/design/MinStack.java | //Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
//push(x) -- Push element x onto stack.
//pop() -- Removes the element on top of the stack.
//top() -- Get the top element.
//getMin() -- Retrieve the minimum element in the stack.
/**
* Your MinStack object will be in... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/design/InsertDeleteGetRandomO1.java | leetcode/design/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/design/ZigZagIterator.java | leetcode/design/ZigZagIterator.java | // Given two 1d vectors, implement an iterator to return their elements alternately.
// For example, given two 1d vectors:
// v1 = [1, 2]
// v2 = [3, 4, 5, 6]
// By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1, 3, 2, 4, 5, 6].
// Follow up: What if you are... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/BinaryTreeVerticalOrderTraversal.java | leetcode/hash-table/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/leetcode/hash-table/IslandPerimeter.java | leetcode/hash-table/IslandPerimeter.java | // You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn't hav... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/EncodeAndDecodeTinyURL.java | leetcode/hash-table/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/leetcode/hash-table/TwoSum.java | leetcode/hash-table/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/leetcode/hash-table/FirstUniqueCharacterInAString.java | leetcode/hash-table/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/leetcode/hash-table/LoggerRateLimiter.java | leetcode/hash-table/LoggerRateLimiter.java | // Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printed in the last 10 seconds.
// Given a message and a timestamp (in seconds granularity), return true if the message should be printed in the given timestamp, otherwise return... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/SingleNumberII.java | leetcode/hash-table/SingleNumberII.java | //Given an array of integers, every element appears three times except for one,
//which appears exactly once. Find that single one.
//Note:
//Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
class SingleNumberII {
public int singleNumber(int[] nums) {
... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/GroupShiftedStrings.java | leetcode/hash-table/GroupShiftedStrings.java | // Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:
// "abc" -> "bcd" -> ... -> "xyz"
// Given a list of strings which contains only lowercase alphabets, group all strings that belong to the same shifting sequence.... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/JewelsAndStones.java | leetcode/hash-table/JewelsAndStones.java | //You're given strings J representing the types of stones that are jewels, and S representing the stones you have.
//Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
//The letters in J are guaranteed distinct, and all characters in J and S are letter... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/DailyTemperatures.java | leetcode/hash-table/DailyTemperatures.java | //Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
//
//For example, given the list temperatures = [73, 74, 75, 71, 69, 72, 76, 73], your out... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/ContainsDuplicatesII.java | leetcode/hash-table/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/leetcode/hash-table/UniqueWordAbbreviation.java | leetcode/hash-table/UniqueWordAbbreviation.java | // An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations:
// a) it --> it (no abbreviation)
// 1
// b) d|o|g --> d1g
// 1 1 1
// 1---5----0----5--8
// c) i|nternationalizatio|... | java | MIT | 03fdcb2703ce72dc0606748733d0c13f09d41d21 | 2026-01-04T14:45:56.686758Z | false |
kdn251/interviews | https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/leetcode/hash-table/MaximumSizeSubarraySumEqualsK.java | leetcode/hash-table/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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.