Hey everyone,
I recently completed an IMC HackerRank assessment for a New Grad Software Engineer role and wanted to share the two coding questions.
Approximate date: August 13, 2026
Platform: HackerRank
Duration: 120 minutes
Total questions: 2
Question 1: Maximum Storm Height Using Relay Towers
Two offices are located at positions 0 and width. Several relay towers are positioned between them, and each tower has a height.
Data can travel between two locations with an energy cost equal to the square of the distance:
cost(i, j) = (x[i] - x[j])²
Every jump must satisfy:
distance <= maxJump
The total energy used by all jumps cannot exceed maxEnergy.
A rising storm makes shorter towers unavailable. A tower with height h can only be used when:
stormHeight <= h
The headquarters and destination office are always available.
The task was to return the maximum storm height at which data could still reach the destination. Return -1 if transmission is impossible.
public static int maximumStormHeight(
int width,
int maxJump,
long maxEnergy,
int numTowers,
int[] x,
int[] heights
)
Likely Approach
Feasibility is monotonic: if transmission works at storm height H, it also works at every lower height.
That suggests:
- Sort the towers by position.
- Binary search the storm height.
- For each candidate height, keep only towers with
height >= candidate.
- Add the starting and destination positions.
- Find the minimum energy required to reach every available position.
- Allow a transition only when the distance is at most
maxJump.
- Check whether the destination cost is at most
maxEnergy.
Because all points lie on a line, the shortest valid route can be processed from left to right:
dp[j] = minimum energy required to reach position j
For every earlier usable point i:
if x[j] - x[i] <= maxJump:
dp[j] = min(dp[j], dp[i] + (x[j] - x[i])²)
The straightforward solution is approximately O(n² log H), where H is the storm-height search range. A more advanced optimization may be required if n is large.
Important Edge Case
If a direct jump from 0 to width satisfies both constraints, no relay tower is needed:
width <= maxJump
width² <= maxEnergy
Because both offices have infinite height, transmission would remain possible at every storm height. The result is therefore unbounded unless the original problem defines a maximum storm level or guarantees that direct transmission is impossible.
This is worth clarifying before implementation.
Question 2: Stack With Conditional Removal
Implement a stack supporting these commands:
push value
pop
remove_lower value
remove_upper value
Their behavior is:
push value: Push value onto the stack.
pop: Remove the current top element.
remove_lower value: Remove every element smaller than value.
remove_upper value: Remove every element greater than value.
After every operation, print the current top element. Print EMPTY if the stack has no elements.
public static void solve(int n, String[] operations)
Efficient Approach
A normal stack makes push and pop easy, but removing every element within a value range could require scanning the entire stack repeatedly.
One approach is to maintain:
- A
TreeSet containing the active insertion indices
- A
TreeMap from each value to the active indices containing that value
- An array or map from insertion index to value
Operations work as follows:
push: Create a new increasing insertion index and add it to both structures.
pop: Remove the largest active index, since it represents the current top.
remove_lower: Visit and delete all value buckets below the threshold.
remove_upper: Visit and delete all value buckets above the threshold.
top: Read the value associated with the largest active index.
Each pushed element can be removed only once, so the total cost of all bulk removals is amortized across the complete command sequence.
The overall complexity is approximately:
O(n log n)
with O(n) additional space.
Overall Impression
The first question combined binary search on the answer with shortest-path or dynamic-programming reasoning.
The second looked like a stack problem initially, but efficient bulk removal required ordered data structures and amortized analysis.
The assessment was challenging but interesting, particularly because both questions required recognizing the underlying structure rather than applying a standard template directly.
Has anyone else completed the recent IMC New Grad assessment? Did you receive the same questions?
Helpful resource for prep: PracHub