Back to EditorCheapC0de
CheapC0de

Problem Set

A curated set of algorithm problems — six general practice problems and fifteen extracted from the Infosys SP/DSE mock test series. Custom questions you add appear here too.

Total
123
Solved
0
Attempted
0
Remaining
123
1

Sliding Window Min Sum

EasyGeneralArraySliding Window
O(n) time, O(k) space8 tests
2

Constrained String Counter

MediumGeneralDynamic ProgrammingStrings
O(n) time, O(1) space9 tests
3

Maximum Non-Adjacent Sum

MediumGeneralArrayDynamic Programming
O(n) time, O(1) space8 tests
4

Triangle Maximum Path Sum

HardGeneralArrayDynamic Programming
O(n²) time, O(n) space8 tests
5

Max Area Container

EasyGeneralArrayTwo Pointers
O(n) time, O(1) space9 tests
6

Valid Parentheses

EasyGeneralAppleStringStack
O(n) time, O(n) space9 tests
I1

Largest Rectangle in Histogram

EasyInfosysArrayStack
O(n) time, O(n) space8 tests
I2

Trapping Rain Water

EasyInfosysGeneralFlipkartGoldman SachsArrayTwo Pointers
O(n) time, O(1) space8 tests
I3

Count Inversions

MediumInfosysArrayDivide and Conquer
O(n log n) time, O(n) space8 tests
I4

Valid Anagram Pairs

EasyInfosysArrayHashing
O(n * L log L) time, O(n*L) space8 tests
I5

Count Primes

EasyInfosysMathSieve of Eratosthenes
O(n log log n) time, O(n) space8 tests
I6

Max Character Frequency

EasyInfosysStringHashing
O(n) time, O(1) space (bounded alphabet)8 tests
I7

GCD of Array

EasyInfosysArrayMath
O(n log M) time, O(1) space8 tests
I8

Jump Game Min Jumps

MediumInfosysArrayGreedy
O(n) time, O(1) space8 tests
I9

Best Time to Buy and Sell Stock

EasyInfosysAdobeAppleArrayGreedy
O(n) time, O(1) space8 tests
I10

Min Insertions Palindrome

MediumInfosysStringsDynamic Programming
O(n^2) time, O(n^2) space8 tests
UG1

Maximum Subarray (Kadane's Algorithm)

MediumGeneralArrayDynamic Programming
O(n) time, O(1) space8 tests
UG2

LRU Cache

MediumGeneralAmazonUberAppleHash TableLinked List
O(1) per op, O(n) total8 tests
UG4

Longest Substring Without Repeating Characters

MediumGeneralFlipkartAdobeMetaHash TableString
O(n) time, O(min(n, a)) space9 tests
UG5

Course Schedule

MediumGeneralFlipkartUberDepth-First SearchBreadth-First Search
O(V + E) time, O(V + E) space8 tests
UG6

Clone Graph

MediumGeneralMetaHash TableDepth-First Search
O(V + E) time, O(V) space7 tests
UG7

Number of Islands

MediumGeneralAmazonUberAdobeAppleArrayDepth-First Search
O(m * n) time, O(m * n) space8 tests
UG8

Word Ladder

HardGeneralHash TableString
O(L * 26 * N) time, O(N) space8 tests
UG9

Shortest Path in a Weighted Graph (Dijkstra's Algorithm)

MediumGeneralGraphHeap (Priority Queue)
O((V + E) log V) time, O(V + E) space8 tests
UG10

Median of Two Sorted Arrays

HardGeneralAppleArrayBinary Search
O(log(min(m, n))) time, O(1) space8 tests
UG11

Search in Rotated Sorted Array

MediumGeneralAdobeArrayBinary Search
O(log n) time, O(1) space8 tests
UG12

Longest Palindromic Substring

MediumGeneralGoldman SachsStringDynamic Programming
O(n^2) time, O(1) space9 tests
UG13

Alien Dictionary

HardGeneralUberArrayHash Table
O(C + V + E) time, O(V + E) space9 tests
UG14

Lowest Common Ancestor of a Binary Tree

MediumGeneralFlipkartAdobeMetaTreeDepth-First Search
O(n) time, O(n) space8 tests
UG15

Sliding Window Maximum

HardGeneralAmazonArrayQueue
O(n) time, O(k) space8 tests
AM1

Serialize and Deserialize Binary Tree

HardAmazonFlipkartTreeDesign
O(n) time, O(n) space8 tests
AM4

Topological Sort

MediumAmazonGraphTopological Sort
O((V + E) log V) time, O(V) space9 tests
AM5

Detect Cycle in a Directed Graph

MediumAmazonGraphDFS
O(V + E) time, O(V + E) space9 tests
AM6

Find the Celebrity

MediumAmazonGraphGreedy
O(n^2) time (matrix check), O(1) space9 tests
AM8

Minimum Window Substring

HardAmazonMetaStringSliding Window
O(m + n) time, O(1) space (alphabet is bounded)9 tests
AM9

Vertical Order Traversal of a Binary Tree

MediumAmazonTreeDFS
O(n log n) time, O(n) space9 tests
AM10

Boolean Parenthesization

HardAmazonMicrosoftDynamic ProgrammingString
O(n^3) time, O(n^2) space9 tests
AM11

Largest Number

MediumAmazonArraySorting
O(n log n * L) time, O(n * L) space (L = average digit length)9 tests
AM12

Rotate Image

MediumAmazonArrayMath
O(n^2) time, O(1) extra space (in-place variant)9 tests
AM13

Diameter of Binary Tree

EasyAmazonTreeDFS
O(n) time, O(n) space (recursion stack)9 tests
AM14

Minimum Path Sum

MediumAmazonArrayDynamic Programming
O(m * n) time, O(n) space (single-row DP)9 tests
AM15

Palindrome Partitioning II

HardAmazonDynamic ProgrammingString
O(n^2) time, O(n^2) space9 tests
MS1

The Celebrity Problem

MediumMicrosoftArrayGreedy
O(n) time, O(1) space8 tests
MS2

Binary Tree Level Order Traversal

MediumMicrosoftTreeBFS
O(n) time, O(n) space8 tests
MS3

Path Sum

EasyMicrosoftTreeDFS
O(n) time, O(h) space (h = tree height)8 tests
MS4

Transform to Sum Tree

MediumMicrosoftTreeDFS
O(n) time, O(h) space8 tests
MS5

Delete the Middle Node of a Linked List

MediumMicrosoftLinked ListTwo Pointers
O(n) time, O(1) space8 tests
MS6

Find All Anagrams in a String

MediumMicrosoftStringSliding Window
O(n) time, O(1) space (26 letters)8 tests
MS7

Remove Duplicate Characters

EasyMicrosoftStringHash Table
O(n) time, O(k) space (k = alphabet size)8 tests
MS8

Encode and Decode TinyURL

MediumMicrosoftHash TableDesign
O(1) per operation (amortized), O(n) space for n URLs8 tests
MS9

Flatten a Multilevel Doubly Linked List

MediumMicrosoftLinked ListDFS
O(n) time, O(d) space (d = max nesting depth)8 tests
MS10

Integer to English Words

HardMicrosoftMathString
O(log n) time (number of chunks), O(1) space8 tests
MS11

Excel Sheet Column Title

EasyMicrosoftMathString
O(log₂₆ n) time, O(log₂₆ n) space8 tests
MS13

Convert Binary Tree to Doubly Linked List

MediumMicrosoftTreeDFS
O(n) time, O(h) space (recursion stack)8 tests
MS14

Remove Loop in Linked List

MediumMicrosoftLinked ListTwo Pointers
O(n) time, O(1) space8 tests
MS15

Copy List with Random Pointer

MediumMicrosoftMetaLinked ListHash Table
O(n) time, O(n) space8 tests
FK3

Merge Intervals

MediumFlipkartAppleMetaArraySorting
O(n log n) time, O(n) space8 tests
FK4

Next Permutation

MediumFlipkartArrayTwo Pointers
O(n) time, O(n) space (returns a new array)9 tests
FK7

Network Delay Time

MediumFlipkartGraphHeap (Priority Queue)
O(E log V) time, O(V + E) space9 tests
FK9

Longest Increasing Subsequence

MediumFlipkartArrayBinary Search
O(n log n) time, O(n) space9 tests
FK10

Edit Distance

HardFlipkartStringDynamic Programming
O(m * n) time, O(m * n) space8 tests
FK11

Coin Change

MediumFlipkartArrayDynamic Programming
O(amount * coins.length) time, O(amount) space9 tests
FK12

Meeting Rooms II

MediumFlipkartUberArrayTwo Pointers
O(n log n) time, O(n) space8 tests
FK13

Job Sequencing Problem

MediumFlipkartGreedySorting
O(N log N) time, O(maxDeadline) space8 tests
FK14

Maximum Sum Subarray of Size K

EasyFlipkartArraySliding Window
O(n) time, O(1) space9 tests
FK15

Largest BST Subtree

MediumFlipkartDynamic ProgrammingTree
O(n) time, O(h) space (recursion stack)8 tests
GS1

0/1 Knapsack with Category Constraint

MediumGoldman SachsDynamic ProgrammingArray
O(C * W * maxGroupSize) time, O(W) space8 tests
GS2

Longest Increasing Subsequence with Difference Constraint

MediumGoldman SachsDynamic ProgrammingArray
O(n^2) time, O(n) space8 tests
GS3

Most Frequent IP Address in a Log File

EasyGoldman SachsStringHash Table
O(L * avgLineLen) time, O(distinct IPs) space8 tests
GS4

Implement Your Own parseInt()

EasyGoldman SachsStringMath
O(n) time, O(1) space8 tests
GS5

Decode a Recursively Encoded String

MediumGoldman SachsStringStack
O(n) time, O(depth) space8 tests
GS6

Minimum Flips to Alternate a Binary String

MediumGoldman SachsStringGreedy
O(n) time, O(1) space8 tests
GS7

House Robber

MediumGoldman SachsArrayDynamic Programming
O(n) time, O(1) space8 tests
GS8

Count Pairs with Sum Divisible by K

MediumGoldman SachsArrayHash Table
O(n + k) time, O(k) space8 tests
GS9

Next Largest Palindromic Number

HardGoldman SachsStringMath
O(d) time where d = number of digits, O(d) space8 tests
GS10

Fibonacci Number

EasyGoldman SachsMathDynamic Programming
O(n) time, O(1) space8 tests
GS11

Climbing Stairs

EasyGoldman SachsMathDynamic Programming
O(n) time, O(1) space8 tests
GS12

Linked List Cycle

EasyGoldman SachsAppleLinked ListTwo Pointers
O(n) time, O(1) space8 tests
GS14

Longest Subarray with Bounded Difference

MediumGoldman SachsArraySliding Window
O(n) time, O(n) space8 tests
GS15

Implement Queue using Stacks

EasyGoldman SachsStackDesign
O(1) amortized per operation8 tests
GS16

House Robber II

MediumGoldman SachsArrayDynamic Programming
O(n) time, O(1) space8 tests
GS17

Binary Tree Zigzag Level Order Traversal

MediumGoldman SachsTreeBreadth-First Search
O(n) time, O(n) space8 tests
GS18

Second Largest Element in a Single Pass

EasyGoldman SachsArray
O(n) time, O(1) space8 tests
GS19

Max Consecutive Ones III

MediumGoldman SachsArraySliding Window
O(n) time, O(1) space8 tests
GS20

Valid Anagram

EasyGoldman SachsStringHash Table
O(n) time, O(1) space8 tests
GS21

Insert and Delete in a Doubly Linked List

EasyGoldman SachsLinked ListDesign
O(pos) per operation (or O(1) for head/tail)9 tests
GS22

Sort Colors

MediumGoldman SachsArrayTwo Pointers
O(n) time, O(1) space8 tests
GS23

Kth Smallest Element in a BST

MediumGoldman SachsTreeBinary Search Tree
O(H + k) time, O(H) space (H = tree height)8 tests
GS24

Reverse Linked List

EasyGoldman SachsAdobeAppleLinked ListRecursion
O(n) time, O(1) space8 tests
GS26

Longest Subarray with Sum Zero

MediumGoldman SachsArrayHash Table
O(n) time, O(n) space8 tests
GS27

Binary Tree Right Side View

MediumGoldman SachsTreeBreadth-First Search
O(n) time, O(n) space8 tests
GS28

Minimum Number of Platforms Required

MediumGoldman SachsArraySorting
O(n log n) time, O(n) space (for sorted copies)8 tests
GS29

Snakes and Ladders

MediumGoldman SachsBreadth-First SearchArray
O(n^2) time and space8 tests
UB1

Bus Routes

HardUberArrayBFS
O(N) time, O(N) space where N = total number of stops across all routes10 tests
UB3

Number of Islands II

HardUberUnion FindDisjoint Set
O(k · α(m·n)) time where k = number of operations, α is the inverse Ackermann; O(m·n) space10 tests
UB4

Design Hit Counter

MediumUberDesignQueue
O(1) amortized per hit and per getHits; O(h) space where h = hits in the last 300s10 tests
UB6

Spiral Matrix

MediumUberArrayMatrix
O(m·n) time, O(1) extra space (excluding output)10 tests
UB7

Word Search

MediumUberBacktrackingDFS
O(m·n·3^L) time where L = word length; O(L) recursion stack space11 tests
UB9

Top K Frequent Elements

MediumUberHash TableHeap
O(n) time with bucket sort, O(n) space; O(n log k) with a size-k heap10 tests
UB10

Evaluate Division

MediumUberGraphBFS
O(Q · (V + E)) time where Q = queries; O(V + E) space10 tests
UB11

Random Pick with Weight

MediumUberBinary SearchPrefix Sum
O(log n) per pickIndex after O(n) prefix-sum precomputation; O(n) space10 tests
UB12

Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

MediumUberSliding WindowMonotonic Deque
O(n) time, O(n) space (two deques)10 tests
UB14

Find Median from Data Stream

HardUberDesignHeap
O(log n) per addNum with two heaps, O(1) per findMedian; O(n) space10 tests
AD2

Second Largest Element in an Array

EasyAdobeArraySingle Pass
O(n) time, O(1) space9 tests
AD4

Symmetric Tree

EasyAdobeTreeDFS
O(n) time, O(h) space (recursion stack)8 tests
AD7

Middle of the Linked List

EasyAdobeLinked ListTwo Pointers
O(n) time, O(1) space9 tests
AD8

Palindromic Substrings

MediumAdobeStringsDynamic Programming
O(n^2) time, O(1) space9 tests
AD9

3Sum

MediumAdobeAppleMetaArrayTwo Pointers
O(n^2) time, O(1) space (excluding output)9 tests
AD10

Container With Most Water

MediumAdobeArrayTwo Pointers
O(n) time, O(1) space9 tests
AD13

Rotting Oranges

MediumAdobeBFSMatrix
O(m·n) time, O(m·n) space9 tests
AD14

LFU Cache

HardAdobeDesignHash Table
O(1) average time per get/put, O(n) space8 tests
AD15

Implement Merge Sort

MediumAdobeSortingDivide and Conquer
O(n log n) time, O(n) auxiliary space9 tests
AP1

Two Sum

EasyAppleArrayHash Table
O(n) time, O(n) space8 tests
AP3

Add Two Numbers

MediumAppleMetaLinked ListMath
O(max(m, n)) time, O(max(m, n)) space9 tests
AP6

Group Anagrams

MediumAppleMetaArrayHash Table
O(n * k log k) time, O(n * k) space where k = max string length8 tests
AP9

Word Break

MediumAppleArrayHash Table
O(n^2 * k) time, O(n) space — k = max word length9 tests
AP11

Product of Array Except Self

MediumAppleMetaArrayPrefix Sum
O(n) time, O(1) extra space8 tests
AP15

Merge Sorted Array

EasyAppleArrayTwo Pointers
O(m + n) time, O(1) extra space (in-place)9 tests
MT6

Subarray Sum Equals K

MediumMetaArrayHashing
O(n) time, O(n) space9 tests
MT9

Validate Binary Search Tree

MediumMetaTreeBinary Search Tree
O(n) time, O(h) space (h = tree height)9 tests
MT10

Binary Tree Maximum Path Sum

HardMetaTreeDFS
O(n) time, O(h) space9 tests
MT13

Is Graph Bipartite?

MediumMetaGraphBFS
O(V + E) time, O(V) space9 tests
MT14

Permutations

MediumMetaBacktrackingRecursion
O(n * n!) time, O(n) extra space (excluding output)9 tests