Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

coding-questions

> 编程语言
Open source

Coding interview questions with solutions (deprecated)

398 stars0 likes1 views
WebsiteGitHub

About

Coding interview questions with solutions (deprecated)

Coding interview questions with solutions from top IT companies and hot startups

Table of Contents

  • Statement
  • Problem
    • Array
    • String
    • Linked List
    • Heap
    • Tree
    • Math
    • Bit Manipulation
    • Graph
    • Sortiing and Search
    • Dynamic Programming
    • Other

⬆ Statement:

Most questions come from IT company interview. Some solutions are NOT my original work, but I don't know who wrote them. Difficulty of questions changes greatly, and the special topics include several advanced ones.

Total Number (not including the problem in the special topics) of Problems: about 210 (120 done).

Although I try to execute every program, bugs may still exist because I didn't run enough tests, welcome to find bugs. The solution may not be optimal, welcome to give your better solution. You can send the corresponding pull request.

By default, the time complexity indicates the worst time and the space complexity doesn't include the stack space.


⬆ Problem:

⬆ Array:

  • Calculate the rotation distance for a sorted rotated array
  • Celebrity problem
  • Detect cycle in an array
  • Detect the longest cycle in an array
  • Diagonal elements sum of a spiral matrix
  • Find a partition in an array to minimize the sum of two parts
  • Find a small rectangle with four corners one in a large rectangle
  • Find elements in the first array but not in the second one
  • Find independent parts in an array
  • Find the id with most posts
  • Find the largest sum of three integers in a row in an array
  • Find the longest consecutive increasing subarray in a grid
  • Find the maximal item a[i], such that a[i]=a[x]+a[y] in an array
  • Find the minimal difference between two sorted arrays
  • Form an ascending array by removing elements from an existed array
  • Given an array a[i], build b[i] = a[0]a[1]…a[n-1]/a[i]
  • Given an array and a number k, check if there exists an element arr[i] such that its duplicates lies in arr[i-k] and arr[i+k]
  • Given an array of size n, the array contains numbers in range from 0 to k-1 where k is a positive integer and k s3 s5 <s6 ...
  • Given an unsigned integer array with size n, the sum of array equals a, calculate a number k such that the sum of array becomes b when all numbers in the array greater than k is replaced by k
  • Given m number of sets, generate a new array arr (size m), where a[i] comes from set i, output all possible new arrays
  • Given three arrays, select each number a, b, c from each array to minimize max(a-b,b-c,c-a)
  • Given two binary arrays A and B, i.e., containing only 0s and 1s each of size N. Find indices i, j such that sum of elements from i to j in both arrays is equal and j-i (i.e. the length of the set i,j) is the maximum possible value
  • Length of first subarray that sums to zero in an array
  • Length of shortest subarray with sum greater than s in in array
  • Nearest greatest element in an array
  • Print all K-complementary in an array
  • Recover the queue
  • Running average in a sliding window
  • Stable two way partition
  • Water flow path

--

⬆ String:

  • Binary string matching
  • Check whether two strings match by insert or delete or replace one char
  • Delete repeating strings
  • Find a vowel product sum of an ASCII string
  • Find the first anagram of a given string in another string
  • Find the replace rule
  • Generate all possible interleaves of two input strings
  • Generate parentheses with different types
  • Given a dictionary and a word, find all words with edit distance<=1 in this dictionary
  • Given a string, delete all char A,and double all char B
  • Given a string, print out the chars with maximal number of consecutive counts
  • Given a string s and a dictionary, find the word break way of the string with minimal number of words
  • Given a string s, check whether it is k duplicates of a string t
  • Given k numbers, get a target with certain arithmetic operators
  • Given string of digits, insert addition operator in between to make sum to be a value
  • Given two string arrays, sort the strings in first array according to the strings order in second one
  • Implement regular expression
  • Implement string.split()
  • Isomorphic Strings
  • Longest substring containing just two unique chars
  • Longest substring which appears more than once
  • Longest substring which begins and ends with two unique chars
  • Name numbers
  • One-byte or two-byte encoding
  • Ordered minimum window substring
  • Pair with largest common words
  • Permutation array of strings
  • Remove comments
  • Reverse index search
  • String encode and decode
  • Two Words
  • Valid Phone Number

--

⬆ Linked List:

  • Flatten a list
  • Given linked list as a-x-b-y-c-z, output it as a-b-c-z-y-x
  • Insert a node into a cyclic Sorted List
  • List Level Sum

--

⬆ Heap:

  • Kth maximal element of array c, where c[k]=a[i]+b[j], a, b are another two arrays
  • Sliding Window Maximum
  • Two dimensional top k elements
  • Water in a two dimensional histogram

--

⬆ Tree:

  • Binary search tree Iterator
  • Binary tree Iterator
  • Check whether a tree exists
  • Construct a tree by a list of pairs
  • Construct a xml tree
  • Find the largest BST subtree in a binary tree
  • Find the right most node in each level of binary tree
  • Flip a binary tree
  • Generate all binary trees according to preorder traversal
  • Heapify a binary tree
  • Immediate right neighbor of given node (parent links, no root) in a binary tree
  • Implement getNextNode()
  • Large tree preorder traversal
  • Longest distance between two nodes of a binary tree
  • Maximal path sum of a n-way tree
  • Morris traversal of a binary tree
  • PreInPostorder travel of a binary tree with stack
  • Printing all nodes at a given distance from a starting node in a binary tree
  • Second largest node in BST
  • SerializeDeSerialize a binary search tree
  • SerializeDeSerialize a binary tree
  • SerializeDeSerialize an arbitrary nodes tree
  • Shortest distance between two nodes of a binary tree
  • Size of the largest complete subtree in a binary tree
  • Statistical binary search tree
  • Switch a binary tree to make equal
  • Trim a binary search tree
  • Total weight of a subtree below this node in a binary tree
  • Vertical sum in a binary tree

--

⬆ Math:

  • Angle between the hour and minute hands
  • Calculate (m^n)%(10^k)
  • Change a m base number to a n base number
  • Delete k digits from a number to get minimal number
  • Divide a plane of points into two equal halves
  • Factorial digit sum
  • Find all numbers less than N, such that n = a^3 + b^3 = c^3 + d^3
  • Find k from 1~n such that k=a^2 +b^2 (a, b positive integer)
  • Find largest triangle in convex hull aside from brute force search
  • Find the complement domino pairs
  • Find the LCM and GCD of two numbers
  • Find the longest 0s surrounded by 1s in a binary expression
  • Form a triangle
  • For some N, print all the solutions of AB = CD where A, B, C, D are all 1~N
  • GetDecimal
  • Get original number including digit 7
  • Given a list of integers of length n in the range of 1 to n-1, find the duplicate element (only one duplicate)
  • Given a positive integer N, print all combinations of non-negative integer sum to N
  • Happy Number
  • Highest 1 position of binary expression
  • Implement the cancall() function
  • Last digit of a^b
  • Magic Number
  • Neare

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言