Placement PrepCoding Practice

Coding Practice

Curated DSA problems from LeetCode, HackerRank, and past company papers to crack the technical rounds.

1Arrays & Strings

Q: Two Sum

A:

Use a Hash Map to store elements and their indices as you iterate. O(N) time complexity.

Q: Valid Parentheses

A:

Use a Stack. Push opening brackets, pop and compare for closing brackets.

Q: Maximum Subarray (Kadane's Algorithm)

A:

Maintain a current_sum and max_sum. If current_sum becomes negative, reset it to 0.

2Linked Lists & Trees

Q: Reverse a Linked List

A:

Maintain three pointers: prev, current, and next. Iterate and reverse links.

Q: Detect Cycle in Linked List

A:

Use Floyd's Tortoise and Hare algorithm (slow and fast pointers).

Q: Lowest Common Ancestor of a BST

A:

If both nodes are less than root, go left. If both are greater, go right. Else, root is LCA.