DEV Community

Cover image for HRT OA 2026 CodeSignal Review (July 27): All 4 Questions with Complete Python Solutions
interviewshow-cs
interviewshow-cs

Posted on

HRT OA 2026 CodeSignal Review (July 27): All 4 Questions with Complete Python Solutions

I recently completed Hudson River Trading's latest Online Assessment on CodeSignal. Like TikTok, Uber, Visa, and Capital One, HRT uses the standard CodeSignal 70-minute, 4-question assessment.

One important observation is that these companies generally do not write their own OA questions. Instead, the problems are sampled from the shared CodeSignal question pool, meaning the overall structure is surprisingly consistent:

  • Question 1 — Easy implementation
  • Question 2 — Easy simulation
  • Question 3 — Matrix / grid simulation
  • Question 4 — Data structure optimization (usually the deciding problem)

This article walks through all four questions, provides complete Python implementations, analyzes the time complexity, and takes a deeper look at the interval-merging problem that appeared in Question 4.


Question 1 — Maximum Rating-to-Price Ratio

You're given two integer arrays, prices and ratings. Find the index whose rating / price ratio is the largest. If multiple products share the same ratio, return the smallest index.

The solution is a simple linear scan. Instead of using floating-point division, compare fractions using cross multiplication:

rating1 * price2 > rating2 * price1

This completely avoids floating-point precision issues while remaining O(n).

Python Solution


def solution(prices, ratings):
    best = 0
    for i in range(1, len(prices)):
        if ratings[i] * prices[best] > ratings[best] * prices[i]:
            best = i
    return best

Time Complexity: O(n)


Question 2 — Bird Nest Simulation

A bird starts at an empty location inside an array representing a forest. Positive numbers represent stick lengths while zero indicates empty ground.

The bird first flies to the right to collect the nearest stick, then to the left, alternating directions until the total collected length reaches at least 100.

This is a straightforward simulation using two pointers. Maintain one pointer moving left and another moving right, alternately searching for the next available stick while marking collected sticks as zero.

Python Solution


def solution(forest, bird):
    n = len(forest)
    total = 0
    left = bird - 1
    right = bird + 1
    go_right = True

    while total < 100:
        if go_right:
            while right < n and forest[right] == 0:
                right += 1
            if right < n:
                total += forest[right]
                forest[right] = 0
                right += 1
        else:
            while left >= 0 and forest[left] == 0:
                left -= 1
            if left >= 0:
                total += forest[left]
                forest[left] = 0
                left -= 1

        go_right = not go_right

        if left < 0 and right >= n:
            break

    return total

Time Complexity: O(n)


Question 3 — Longest Diagonal Pattern Matching

Given a matrix containing only 0, 1, and 2, find the longest diagonal sequence matching:


1, 2, 0, 2, 0, 2, 0...

The pattern begins with a single 1, followed by an infinite alternating sequence of 2 and 0. The diagonal may extend in any of the four diagonal directions, but the final cell must lie on the matrix boundary.

The official complexity limit is generous enough that brute force is acceptable. Enumerate every starting position containing 1 and extend along all four diagonal directions.

Python Solution


def expected(pos):
    if pos == 0:
        return 1
    return 2 if pos % 2 else 0

def solution(matrix):
    m = len(matrix)
    n = len(matrix[0])

    dirs = [
        (-1,-1),
        (-1,1),
        (1,-1),
        (1,1)
    ]

    best = 0

    def border(r,c):
        return r==0 or r==m-1 or c==0 or c==n-1

    for i in range(m):
        for j in range(n):
            if matrix[i][j] != 1:
                continue

            for dr,dc in dirs:
                r,c=i,j
                pos=0
                length=0

                while 0<=r

Time Complexity: O(m²n²)


Question 4 — Total Unique Bytes After Every Segment (Interval Merging)

This is the most important question in the OA.

Each segment is represented as a closed interval:

[start, end]

The values are 64-bit integers, meaning the coordinate range may reach 1018. After every new segment arrives, output the total number of unique covered bytes.

Two observations immediately determine the solution:

  • You cannot mark every byte individually because the coordinate range is enormous.
  • The answer must be updated dynamically after each insertion.

Instead, maintain a collection of non-overlapping intervals together with the current total covered length. Whenever a new interval arrives:

  1. Find every existing interval that overlaps (or touches) it.
  2. Merge them into one larger interval.
  3. Subtract the lengths of removed intervals.
  4. Add the merged interval length.
  5. Output the running total.

Although Python's sortedcontainers.SortedList provides an elegant solution, CodeSignal does not always include third-party libraries. The following implementation uses only bisect.

Python Solution


import bisect

def solution(segments):

    starts=[]
    intervals=[]

    total=0
    ans=[]

    for s,e in segments:

        idx=bisect.bisect_left(starts,s)

        if idx>0 and intervals[idx-1][1]>=s-1:
            idx-=1

        newL,newR=s,e

        i=idx

        while i=newL-1:

                newL=min(newL,L)
                newR=max(newR,R)

                total-=R-L+1

                starts.pop(i)
                intervals.pop(i)

            else:
                i+=1
                break

        total+=newR-newL+1

        pos=bisect.bisect_left(starts,newL)

        starts.insert(pos,newL)
        intervals.insert(pos,[newL,newR])

        ans.append(total)

    return ans

If the problem considers adjacent intervals continuous (for example, [1,2] and [3,3]), merge whenever end >= start - 1. If adjacency should remain separate, simply remove the ±1 adjustments. The overall algorithm remains identical.

Average Time Complexity: O(n log n)


Complexity Summary

Question Approach Complexity
Q1 Linear Scan + Cross Multiplication O(n)
Q2 Two-Pointer Simulation O(n)
Q3 Brute Force Matrix Enumeration O(m²n²)
Q4 Dynamic Interval Merging O(n log n)

Preparation Tips

This OA once again demonstrates the standard CodeSignal pattern used by many companies. The first two questions are generally straightforward implementation problems and should ideally be completed within the first 20 minutes. Question 3 is usually manageable through careful simulation, while Question 4 almost always determines whether candidates pass.

Common advanced topics appearing in the final question include:

  • Interval Merging
  • Union Find
  • Priority Queues
  • Monotonic Stack
  • Balanced Trees
  • Hash + Ordered Containers

Having these templates ready before the OA can significantly improve your chances of finishing all four questions.


Final Thoughts

The CodeSignal question pool is highly reusable across companies. Hudson River Trading, TikTok, Uber, Visa, and Capital One frequently draw from the same collection of problems, making prior practice extremely valuable.

We've been continuously tracking CodeSignal updates and have organized more than 130 verified CodeSignal questions together with tested Python solutions covering nearly every common pattern.

If you're preparing for HRT or any other company using CodeSignal, you can find more interview experiences, OA writeups, and preparation resources at:

https://interviewshow.com/

Whether you're preparing weeks in advance or have an assessment coming up soon, building familiarity with these recurring patterns is one of the highest-return investments you can make.

Top comments (0)