Baidu Coding Interview Questions
25 Baidu coding interview problems with full optimal solutions — 11 easy, 11 medium, 3 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Baidu interviewer values, and a FAQ section.
Showing 11 problems of 25
- #12mediumfoundational
12. Binary Tree Level Order Traversal
Return the values of a binary tree visited level by level, left to right.
- #13mediumfoundational
13. LRU Cache
Design a fixed-capacity cache that evicts the least-recently-used key when full, supporting get and put in O(1).
- #14mediumfoundational
14. Number of Islands
Count connected components of land cells in a 2D grid where '1' is land and '0' is water.
- #15mediumfoundational
15. Course Schedule
Decide whether all courses can be finished given prerequisite pairs — equivalently, whether a directed graph is acyclic.
- #16mediumfoundational
16. Kth Largest Element in an Array
Find the kth largest element in an unsorted array without fully sorting it.
- #17mediumfoundational
17. Longest Increasing Subsequence
Find the length of the longest strictly increasing subsequence of an integer array.
- #18mediumfoundational
18. Coin Change
Find the fewest coins from a given set of denominations needed to make a target amount, or -1 if impossible.
- #19mediumfoundational
19. Subarray Sum Equals K
Count the number of contiguous subarrays whose elements sum exactly to k.
- #20mediumfoundational
20. Implement Trie (Prefix Tree)
Build a trie supporting insert, search, and startsWith on lowercase ASCII words.
- #21mediumfoundational
21. Find All Anagrams in a String
Return every start index in s where a substring of length |p| is an anagram of p.
- #22mediumfoundational
22. Daily Temperatures
For each day, report how many days you have to wait until a warmer temperature, or 0 if there is none.