Day 15: Sorting & Searching

Interview Coding Problems + QA Relevance

1. Verify if Array is Sorted

Difficulty: Easy | Concept: Sorting

Problem: Write a function to check if a given array is sorted in ascending order.

QA Angle: Often used to validate API responses or test reports where results must appear in sorted order (e.g., products by price, logs by timestamp).

2. Implement Binary Search

Difficulty: Easy-Medium | Concept: Searching

Problem: Given a sorted array of integers and a target, implement binary search to return the index of the target or -1 if not found.

QA Angle: Used in defect isolation — finding the first failing build or log entry faster than linear scans.

3. First and Last Occurrence

Difficulty: Medium | Concept: Binary Search Variants

Problem: In a sorted array with duplicates, find the first and last occurrence of a target element.

QA Angle: Useful in verifying counts of repeated test cases, duplicate log entries, or multiple defect IDs.

4. Kth Smallest Element

Difficulty: Medium | Concept: QuickSelect / Heap

Problem: Find the Kth smallest element in an unsorted array.

QA Angle: Often applied in performance testing (e.g., find 95th percentile response time).

5. Top-K Frequent Elements

Difficulty: Medium | Concept: Heap / Sorting

Problem: Given an array of log entries (strings), return the top K most frequent entries.

QA Angle: Helps in analyzing logs and identifying the most common failures in automation runs.

6. Search in Rotated Sorted Array

Difficulty: Medium | Concept: Binary Search

Problem: Search for a target element in a rotated sorted array.

QA Angle: Used to test data that shifts over releases or cyclic execution orders in regression suites.

7. Merge Intervals

Difficulty: Medium | Concept: Sorting + Greedy

Problem: Given overlapping test execution time intervals, merge them into non-overlapping intervals.

QA Angle: Useful for analyzing overlapping automation jobs, scheduling conflicts, or test bench usage.

8. Meeting Rooms / Minimum Platforms

Difficulty: Medium | Concept: Sorting + Sweep Line

Problem: Given start and end times of multiple test runs, determine the minimum number of labs/benches required.

QA Angle: Practical for resource allocation in test labs — ensures no overbooking of execution environments.

9. Median of Two Sorted Arrays

Difficulty: Hard | Concept: Binary Search Partition

Problem: Find the median of two sorted arrays in O(log(min(m,n))).

QA Angle: Used to analyze and compare median response times from two different environments or releases.

10. Inversion Count

Difficulty: Hard | Concept: Merge Sort

Problem: Count inversions in an array (pairs where arr[i] > arr[j], i < j).

QA Angle: Can represent how much a test sequence deviates from expected sorted order, useful for defect trend analysis.