Online assessment
BARC Coding Questions
Overview
Practice BARC coding questions in the style students report for online assessments and technical interviews. Focus areas: GATE/exam technical depth. Languages commonly allowed: Scientific computing roles vary.
BARC coding pattern
| Item | Typical expectation |
|---|---|
| Problems | 1-3 coding tasks depending on drive |
| Skills | GATE/exam technical depth |
| Languages | Scientific computing roles vary (use what the assessment email lists) |
| What matters | Correctness first, then speed and clear code |
Practice problems
Question 1: reverse a string in place
Coding Q1: Reverse a string in place
Problem: Given a mutable character array representing a string, reverse it in place without allocating another array of the same size.
Approach: Use two pointers at the start and end. Swap characters, then move inward until the pointers meet. Watch empty and single-character inputs.
Complexity: O(n) time, O(1) extra space
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 2: check prime
Coding Q2: Check prime
Problem: Write a function that returns true if n is prime and false otherwise. Handle n < 2 correctly.
Approach: Return false for n < 2. Trial-divide from 2 to floor(sqrt(n)). If any divisor divides n evenly, it is composite; otherwise prime.
Complexity: O(√n) time
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 3: valid parentheses
Coding Q3: Valid parentheses
Problem: Given a string containing only ‘()[]’, decide whether the brackets are balanced and correctly nested.
Approach: Scan left to right with a stack. Push opening brackets. On a closing bracket, the stack top must be the matching opener. At the end the stack must be empty.
Complexity: O(n) time, O(n) space
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 4: two sum
Coding Q4: Two Sum
Problem: Given an array of integers and a target, return indices of two numbers that add up to the target. Assume exactly one solution and you may not use the same element twice.
Approach: Walk the array once. For each value x, check whether target − x was seen earlier in a hash map of value → index. If yes, return both indices; else store x.
Complexity: O(n) time, O(n) space
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 5: longest substring without repeating characters
Coding Q5: Longest substring without repeating characters
Problem: Given a string s, find the length of the longest substring without repeating characters. Example: ‘abcabcbb’ → 3 (‘abc’).
Approach: Sliding window with a map (or last-seen index) of characters. Expand the right pointer; when a duplicate appears inside the window, move the left pointer past the previous occurrence.
Complexity: O(n) time
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 6: merge overlapping intervals
Coding Q6: Merge overlapping intervals
Problem: Given a list of intervals [start, end], merge all overlapping intervals and return the non-overlapping set that covers the same ranges.
Approach: Sort by start time. Walk once, merging into the last interval in the result when the next start is ≤ current end; otherwise append a new interval.
Complexity: O(n log n) time from the sort
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 7: top k frequent elements
Coding Q7: Top K frequent elements
Problem: Given an integer array and an integer k, return the k most frequent elements. Order among equals can be arbitrary unless the problem says otherwise.
Approach: Count frequencies with a hash map, then use a heap of size k (or bucket sort by frequency) to extract the top k keys.
Complexity: O(n log k) with a heap
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 8: linked list cycle
Coding Q8: Linked list cycle
Problem: Given the head of a linked list, return true if there is a cycle and false otherwise.
Approach: Floyd’s tortoise and hare: move one pointer one step and another two steps. If they meet, a cycle exists. If the fast pointer hits null, there is no cycle.
Complexity: O(n) time, O(1) space
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 9: binary tree level order
Coding Q9: Binary tree level order
Problem: Given the root of a binary tree, return the level-order traversal (breadth-first) as a list of levels.
Approach: Use a queue. For each level, drain the current queue size, collect values, and enqueue children for the next level.
Complexity: O(n) time, O(n) space
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Question 10: coin change
Coding Q10: Coin change (min coins)
Problem: Given coin denominations and an amount, return the fewest coins needed to make that amount, or -1 if it is impossible.
Approach: Unbounded knapsack DP: let dp[x] be the minimum coins for amount x. For each coin, update dp[c..amount]. Initialize dp[0] = 0 and the rest to a large sentinel.
Complexity: O(amount × coins)
BARC tip: Restate the problem, sketch a brute-force idea, then tighten it. Call out edge cases (empty input, single element, overflow) before you write code.
Pattern drill plan (2 weeks)
| Day | Drill |
|---|---|
| Mon | Arrays + hashing (2 problems) |
| Tue | Two pointers / sliding window |
| Wed | Stacks / strings |
| Thu | Trees or graphs basics |
| Fri | Timed mock (1-2 problems) |
| Sat | Re-solve misses cold |
| Sun | Explain your project out loud + rest |

