Daily Coding Interview
  • Aug 22, 2024

    Connected Components in an Undirected Graph [Solution]

  • Aug 21, 2024

    Connected Components in an Undirected Graph

    Given an undirected graph represented as an adjacency list, implement a function to find the number of connected components in the graph.

  • Aug 20, 2024

    Count Bits [Solution]

  • Aug 19, 2024

    Count Bits

    Given a non-negative integer num, create an array result of length num + 1 where each element result[i] represents the number of 1’s in the binary representation of i.

  • Aug 18, 2024

    Missing Positive [Solution]

  • Aug 17, 2024

    Missing Positive

    Given an unsorted integer array, find the smallest missing positive integer.

  • Aug 16, 2024

    Binary Tree Path Sum [Solution]

  • Aug 15, 2024

    Binary Tree Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

  • Aug 14, 2024

    Bitonic Array Maximum [Solution]

  • Aug 13, 2024

    Bitonic Array Maximum

    A bitonic array is an array that starts strictly increasing and then strictly decreasing. Given a bitonic array arr of distinct integers, find the maximum element in the array. You may assume that the array always contains at least one element.

  • Aug 12, 2024

    Inorder Successor in Binary Search Tree [Solution]

  • Aug 11, 2024

    Inorder Successor in Binary Search Tree

    Given a binary search tree (BST) and a node p in it, find the in-order successor of that node in the BST.

  • Aug 10, 2024

    Maximum Subarray Sum [Solution]

  • Aug 9, 2024

    Maximum Subarray Sum

    Given an array of integers, find the contiguous subarray (containing at least one number) that has the largest sum and return its sum.

  • Aug 8, 2024

    Course Schedule [Solution]

  • Aug 7, 2024

    Course Schedule

    There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [y, x] indicates that you must take course x first if you want to take course y.

  • Aug 6, 2024

    Longest Increasing Subsequence [Solution]

  • Aug 5, 2024

    Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of the longest increasing subsequence (LIS).

  • Aug 4, 2024

    Search in Rotated Sorted Array [Solution]

  • Aug 3, 2024

    Search in Rotated Sorted Array

    Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given a target value target, write a function to search for the target in the rotated sorted array.

  • Aug 2, 2024

    Lowest Common Ancestor in Binary Tree [Solution]

  • Aug 1, 2024

    Lowest Common Ancestor in Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes p and q in the tree.

  • Jul 31, 2024

    Symmetric Binary Tree [Solution]

  • Jul 30, 2024

    Symmetric Binary Tree

    Given a binary tree, check whether it is a symmetric tree. A symmetric tree is a mirror image of itself with respect to its center.

  • Jul 29, 2024

    Longest Palindromic Substring [Solution]

  • Jul 28, 2024

    Longest Palindromic Substring

    Given a string, find the longest palindromic substring in it. A palindrome is a word, phrase, or sequence that reads the same backward as forward. A substring is a contiguous sequence of characters within the string.

  • Jul 27, 2024

    Longest Common Prefix [Solution]

  • Jul 26, 2024

    Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings.

  • Jul 25, 2024

    Rotate Image [Solution]

  • Jul 24, 2024

    Rotate Image

    You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

  • Jul 23, 2024

    Median of Two Sorted Arrays [Solution]

  • Jul 22, 2024

    Median of Two Sorted Arrays

    You are given two sorted arrays, nums1 and nums2, where nums1 has size m and nums2 has size n. Your task is to find the median of the two sorted arrays. If possible, the overall run time complexity should be O(log(min(m, n))).

  • Jul 21, 2024

    Word Search 2 [Solution]

  • Jul 20, 2024

    Word Search 2

    Given a 2D board of characters and a list of words, find all words in the board.

  • Jul 19, 2024

    Minimize Meeting Rooms [Solution]

  • Jul 18, 2024

    Minimize Meeting Rooms

    Given a list of meetings with start and end times, determine the minimum number of meeting rooms required to accommodate all the meetings. The start and end times of the meetings are represented as tuples (start_time, end_time).

  • Jul 17, 2024

    Minimum Cost to Climb Stairs [Solution]

  • Jul 16, 2024

    Minimum Cost to Climb Stairs

    You are given an array cost where cost[i] is the cost of i-th step on a staircase. You can start from either the 0-th step or the 1-st step. Each step can be climbed by paying the cost specified, and you can either climb one step or two steps at a time.

  • Jul 15, 2024

    Longest Substring with K Distinct Characters [Solution]

  • Jul 14, 2024

    Longest Substring with K Distinct Characters

    Given a string s and an integer k, find the length of the longest substring with at most k distinct characters.

  • Jul 13, 2024

    Reverse a Linked List [Solution]

  • Jul 12, 2024

    Reverse a Linked List

    You are given a singly linked list. Write a function to reverse the linked list.

  • Jul 11, 2024

    Product of Array Except Self [Solution]

  • Jul 10, 2024

    Product of Array Except Self

    Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

  • Jul 9, 2024

    Coin Change [Solution]

  • Jul 8, 2024

    Coin Change

    Given a set of coin denominations and a target amount, determine the minimum number of coins needed to make up that amount.

  • Jul 7, 2024

    Kth Largest Element in an Array [Solution]

  • Jul 6, 2024

    Kth Largest Element in an Array

    Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

  • Jul 5, 2024

    Word Search [Solution]

  • Jul 4, 2024

    Word Search

    Given a 2D board of letters and a word, determine if the word exists in the grid.

  • Jul 3, 2024

    Valid Parentheses [Solution]

  • Jul 2, 2024

    Valid Parentheses

    Given a string containing just the characters (, ), {, }, [ and ], determine if the input string is valid.

  • Jul 1, 2024

    Merge Overlapping Intervals [Solution]

  • Jun 30, 2024

    Merge Overlapping Intervals

    Given a list of intervals, where each interval is represented as a pair of integers [start, end], write a function to merge overlapping intervals.

  • Jun 29, 2024

    Minimum Window Substring [Solution]

  • Jun 28, 2024

    Minimum Window Substring

    Given a string s and a string t, find the minimum window in s that contains all the characters of t in any order. If there is no such window, return an empty string “”.

  • Jun 27, 2024

    Two Sum [Solution]

  • Jun 26, 2024

    Two Sum

    Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to the target.

  • Jun 25, 2024

    Subarray Product Less Than K [Solution]

  • Jun 24, 2024

    Subarray Product Less Than K

    Given an array of positive integers and an integer k, find the number of contiguous subarrays where the product of all the elements is less than k.

  • Jun 23, 2024

    Design a Doubly Linked List [Solution]

  • Jun 22, 2024

    Design a Doubly Linked List

    Design a doubly linked list (DLL) with the following operations:

    1. insert_at_head(val): Insert a node with the given value at the beginning of the doubly linked list.
    2. insert_at_tail(val): Insert a node with the given value at the end of the doubly linked list.
    3. insert_after_node(node, val): Insert a node with the given value after the specified node in the doubly linked list.
    4. delete_at_head(): Delete the node at the beginning of the doubly linked list.
    5. delete_at_tail(): Delete the node at the end of the doubly linked list.
    6. delete_node(node): Delete the specified node from the doubly linked list.
    7. display(): Display the elements of the doubly linked list.
  • Jun 21, 2024

    Word Break [Solution]

  • Jun 20, 2024

    Word Break

    Given a non-empty string and a dictionary containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

  • Jun 19, 2024

    Kth Smallest Element in a Sorted Matrix [Solution]

  • Jun 18, 2024

    Kth Smallest Element in a Sorted Matrix

    Given an n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.

  • Jun 17, 2024

    Maximum Depth of Binary Tree [Solution]

  • Jun 16, 2024

    Maximum Depth of Binary Tree

    Given the root of a binary tree, find its maximum depth.

  • Jun 15, 2024

    Two Sum Less Than K [Solution]

  • Jun 14, 2024

    Two Sum Less Than K

    Given an array nums of integers and an integer k, find two distinct indices i and j in the array such that nums[i] + nums[j] is the maximum possible value less than k. If no such indices exist, return -1.

  • Jun 13, 2024

    Container With Most Water [Solution]

  • Jun 12, 2024

    Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai), n vertical lines are drawn such that the two endpoints of the line i are at (i, ai) and (i, 0). Find two lines, which, together with the x-axis, forms a container that would hold the greatest amount of water. Return the maximum area of the water it can contain.

  • Jun 11, 2024

    Perfect Squares Sum [Solution]

  • Jun 10, 2024

    Perfect Squares Sum

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) that sum up to n.

  • Jun 9, 2024

    Anagram Groups [Solution]

  • Jun 8, 2024

    Anagram Groups

    Given a list of strings, write a function to group the strings into sets of anagrams.

  • Jun 7, 2024

    Sum of Left Leaves in Binary Tree [Solution]

  • Jun 6, 2024

    Sum of Left Leaves in Binary Tree

    Given the root of a binary tree, return the sum of all left leaves.

  • Jun 5, 2024

    Binary Tree Maximum Path Sum [Solution]

  • Jun 4, 2024

    Binary Tree Maximum Path Sum

    Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree.

  • Jun 3, 2024

    Valid Sudoku [Solution]

  • Jun 2, 2024

    Valid Sudoku

    Determine whether a 9 x 9 Sudoku board is valid.

  • Jun 1, 2024

    Longest Consecutive Sequence in an Array [Solution]

  • May 31, 2024

    Longest Consecutive Sequence in an Array

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

  • May 30, 2024

    Kth Smallest Element in a Binary Search Tree [Solution]

  • May 29, 2024

    Kth Smallest Element in a Binary Search Tree

    Given a binary search tree (BST), find the kth smallest element in it.

  • May 28, 2024

    Invert Binary Tree [Solution]

  • May 27, 2024

    Invert Binary Tree

    Given the root of a binary tree, invert the tree by swapping the left and right children of each node.

  • May 26, 2024

    Find the Missing Number [Solution]

  • May 25, 2024

    Find the Missing Number

    You are given an array of length n containing n distinct numbers taken from the range 0 to n. Since the array has n distinct numbers and the numbers are in the range 0 to n, there is exactly one number missing.

  • May 24, 2024

    Sum of Digits Until a Single Digit [Solution]

  • May 23, 2024

    Sum of Digits Until a Single Digit

    Given a non-negative integer, repeatedly add all its digits until the result has only one digit.

  • May 22, 2024

    Unique Paths [Solution]

  • May 21, 2024

    Unique Paths

    A robot is located at the top-left corner of a m x n grid. 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. How many possible unique paths are there?

  • May 20, 2024

    Minimum Cost to Reach Destination in a Weighted Graph [Solution]

  • May 19, 2024

    Minimum Cost to Reach Destination in a Weighted Graph

    You are given a weighted graph represented by an adjacency matrix graph where graph[i][j] represents the cost to move from node i to node j. Each node is labeled from 0 to n-1. You are also given two nodes source and destination.

  • May 18, 2024

    Word Ladder Transformation [Solution]

  • May 17, 2024

    Word Ladder Transformation

    Given two words, beginWord and endWord, and a dictionary of words wordList, find the length of the shortest transformation sequence from beginWord to endWord such that:

  • May 16, 2024

    Binary Tree Level Order Traversal [Solution]

  • May 15, 2024

    Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes’ values. Level order traversal means traversing the tree level by level, from left to right.

  • May 14, 2024

    Merge Sorted Arrays [Solution]

  • May 13, 2024

    Merge Sorted Arrays

    You are given an array of k sorted integer arrays, where each array is sorted in ascending order. Merge these arrays into a single sorted array.

  • May 12, 2024

    Merge K Sorted Linked Lists [Solution]

  • May 11, 2024

    Merge K Sorted Linked Lists

    Merge k sorted linked lists and return it as one sorted list.

  • May 10, 2024

    Shortest Path in Binary Matrix [Solution]

  • May 9, 2024

    Shortest Path in Binary Matrix

    Given a binary matrix representing an obstacle grid where 0 represents an empty cell and 1 represents an obstacle, find the length of the shortest path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1). If there is no path, return -1.

  • May 8, 2024

    Rotate Array to the Right [Solution]

  • May 7, 2024

    Rotate Array to the Right

    Given an array, rotate the array to the right by k steps, where k is a non-negative integer. The function should modify the input array in-place.

  • May 6, 2024

    Find All Anagrams in a String [Solution]

  • May 5, 2024

    Find All Anagrams in a String

    Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.

  • May 4, 2024

    Reverse Linked List [Solution]

  • May 3, 2024

    Reverse Linked List

    Given the head of a singly linked list, reverse the list without modifing the values of the nodes (modify only their pointers).

  • May 2, 2024

    Longest Substring Without Repeating Characters [Solution]

  • May 1, 2024

    Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters.

  • Apr 30, 2024

    Rearrange Array Elements [Solution]

  • Apr 29, 2024

    Rearrange Array Elements

    Given an array of positive integers, rearrange the elements such that the resulting number formed by concatenating the elements is the largest possible number.

  • Apr 28, 2024

    Palindromic Substrings [Solution]

  • Apr 27, 2024

    Palindromic Substrings

    Given a string s, return the number of palindromic substrings in it.

  • Apr 26, 2024

    String Power [Solution]

  • Apr 25, 2024

    String Power

    Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character.

  • Apr 24, 2024

    Spiral Matrix [Solution]

  • Apr 23, 2024

    Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

  • Apr 22, 2024

    Integer Hamming Distance [Solution]

  • Apr 21, 2024

    Integer Hamming Distance

    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 between them.

  • Apr 20, 2024

    Reverse Bits [Solution]

  • Apr 19, 2024

    Reverse Bits

    Given an unsigned integer, reverse its binary representation (i.e., reading it from right to left).

  • Apr 18, 2024

    Maximum Product Subarray [Solution]

  • Apr 17, 2024

    Maximum Product Subarray

    Given an integer array, find the contiguous subarray within the array (containing at least one number) that has the largest product. Return the maximum product.

  • Apr 16, 2024

    Maximum XOR Pair [Solution]

  • Apr 15, 2024

    Maximum XOR Pair

    Given an array of integers, find the maximum XOR value between any two elements in the array.

  • Apr 14, 2024

    Randomized Shuffle [Solution]

  • Apr 13, 2024

    Randomized Shuffle

    Given an array of integers, implement a function to shuffle the array randomly. Each permutation of the array should be equally likely.

  • Apr 12, 2024

    Linked List Cycle [Solution]

  • Apr 11, 2024

    Linked List Cycle

    Given a linked list, determine if it has a cycle in it. A cycle is defined as having at least one node in the list whose next is the node itself.

  • Apr 10, 2024

    Subarray Sum Equals K [Solution]

  • Apr 9, 2024

    Subarray Sum Equals K

    Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k.

  • Apr 8, 2024

    Letter Combinations of a Phone Number [Solution]

  • Apr 7, 2024

    Letter Combinations of a Phone Number

    Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.

  • Apr 6, 2024

    Three Sum [Solution]

  • Apr 5, 2024

    Three Sum

    Given an array nums of n integers, find all unique triplets in the array which gives the sum of zero.

  • Apr 4, 2024

    Reverse Words [Solution]

  • Apr 3, 2024

    Reverse Words

    Given a string containing words separated by spaces, reverse the order of words in the string. For example, given the input string "Hello World", the output should be "World Hello".

  • Apr 2, 2024

    Buy and Sell Stock [Solution]

  • Apr 1, 2024

    Buy and Sell Stock

    You are given an array prices where prices[i] is the price of a given stock on the ith day.

  • Mar 31, 2024

    Find Peak Element [Solution]

  • Mar 30, 2024

    Find Peak Element

    A peak element in an array is an element that is greater than or equal to its neighbors. Given an input array nums where nums[i] != nums[i+1], find a peak element and return its index.

  • Mar 29, 2024

    Anagram Pairs [Solution]

  • Mar 28, 2024

    Anagram Pairs

    Given an array of strings, find the number of pairs of strings that are anagrams of each other. Two strings are considered anagrams if they have the same characters, but in a different order.

  • Mar 27, 2024

    Valid Palindrome [Solution]

  • Mar 26, 2024

    Valid Palindrome

    Given a string, determine if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization.

Subscribe

  • Daily Coding Interview
  • admin@dailycodinginterview.com

Your go-to destination for mastering coding interviews. Packed with a vast collection of carefully curated coding problems and detailed solutions, it is designed to help aspiring developers and seasoned professionals alike excel in technical interviews. Whether you are gearing up for a job opportunity at a top tech company or simply want to sharpen your problem-solving skills, we are here to help you.