Autocoder

NVIDIA Coding Round Questions with Solutions

Last updated 2026-11-19

Coding exercises for GPU and systems software roles usually combine ordinary data-structure problems with parallel patterns written first as clear sequential code: reduction, scan, histogram, tiling. This page gives twelve practice problems in that style, with complete solutions, complexity and the mistakes people make.

These are practice problems for topics the role is commonly reported to cover, not real papers. NVIDIA says technical candidates may code on HackerRank, a whiteboard or a laptop it provides, so practise without autocomplete. Read NVIDIA interview questions for the concept side.

How to practise

Solve each problem sequentially first. Then say how you would parallelise it: which operations are independent, where threads would need to synchronise, and what the memory access pattern looks like. An interviewer often cares more about that discussion than about the final kernel.

Keep a short checklist: input size zero or one, odd sizes, overflow of the sum type, and in-place versus out-of-place updates.

Hiring status

There is no NVIDIA hiring page on this site because no India hiring number or calendar from NVIDIA can be quoted. For openings, use the company's own careers site, and for the process read how to crack the NVIDIA interview.

NVIDIA Coding Round Questions with Solutions: questions with worked answers

  1. 1

    Write a CUDA-style vector add as a sequential loop and explain the mapping.

    easy

    The sequential loop becomes a kernel where each thread handles index i = blockIdx.x * blockDim.x + threadIdx.x, with a bounds guard. The loop has no dependences between iterations, so it parallelises perfectly. Time O(n) work; on p threads the time is about n/p. Common mistake: omitting the guard, so the last block writes past the array when n is not a multiple of the block size.

    c
    #include <stdio.h>
    void add(const float *a, const float *b, float *c, int n) {
        for (int i = 0; i < n; i++) c[i] = a[i] + b[i];
    }
    int main(void) {
        float a[3] = {1, 2, 3}, b[3] = {4, 5, 6}, c[3];
        add(a, b, c, 3);
        printf("%.0f %.0f %.0f\n", c[0], c[1], c[2]); /* 5 7 9 */
        return 0;
    }
  2. 2

    Compute an inclusive prefix sum, then describe a parallel version.

    medium

    Sequentially, out[i] = out[i-1] + in[i], O(n). A parallel scan such as Hillis-Steele does log2(n) rounds; in round d every element adds the element 2^d positions to its left, doing O(n log n) work in O(log n) steps. Blelloch's scan is work-efficient at O(n). In the Python version below, each round reads from a copy so updates do not overwrite values still needed, exactly as a GPU needs double buffering or a barrier. Common mistake: updating in place and getting wrong values.

    python
    def scan(a):
        a = list(a)
        d = 1
        while d < len(a):
            prev = a[:]                     # barrier: read the old values
            for i in range(d, len(a)):
                a[i] = prev[i] + prev[i - d]
            d *= 2
        return a
    
    print(scan([3, 1, 4, 1, 5, 9, 2, 6]))  # [3, 4, 8, 9, 14, 23, 25, 31]
  3. 3

    Sum an array with a tree reduction and state the complexity.

    easy

    Repeatedly add the upper half of the active region to the lower half. Work is n - 1 additions, steps are ceil(log2 n). If n is not a power of two, guard i + stride against the array length. Common mistake: assuming n is a power of two, which reads out of bounds. For floating point, note that the tree order changes rounding compared with a left-to-right sum.

    python
    def tree_sum(a):
        a = list(a)
        n = len(a)
        stride = 1
        while stride < n:
            for i in range(0, n, 2 * stride):
                if i + stride < n:
                    a[i] += a[i + stride]
            stride *= 2
        return a[0]
    
    print(tree_sum([1, 2, 3, 4, 5, 6, 7]))  # 28
  4. 4

    Build a histogram of byte values and explain what makes the parallel version hard.

    medium

    Sequentially, count[data[i]]++ in O(n) with 256 bins. In parallel, many threads may hit the same bin, so you need atomics or per-block private histograms merged at the end. Time O(n + bins). Common mistake: forgetting to zero the counters or using a signed char as an index, which goes negative for values above 127.

    c
    #include <stdio.h>
    #include <string.h>
    int main(void) {
        const unsigned char data[] = {1, 2, 2, 255, 2, 1};
        unsigned count[256];
        memset(count, 0, sizeof count);
        for (size_t i = 0; i < sizeof data; i++) count[data[i]]++;
        printf("%u %u %u\n", count[1], count[2], count[255]); /* 2 3 1 */
        return 0;
    }
  5. 5

    Transpose a matrix in tiles and say why tiling helps.

    medium

    Process the matrix in B by B blocks so that the rows being read and the columns being written both stay in cache (or shared memory on a GPU). The result is identical to the naive loop; only the traversal order changes. Time O(N^2). With B chosen to fit in cache, misses drop sharply. Common mistake: not handling sizes that are not a multiple of B, so use min() on the block bounds.

    c
    #include <stdio.h>
    #define N 5
    #define B 2
    static int min(int a, int b) { return a < b ? a : b; }
    int main(void) {
        int in[N][N], out[N][N];
        for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) in[i][j] = i * N + j;
        for (int ii = 0; ii < N; ii += B)
            for (int jj = 0; jj < N; jj += B)
                for (int i = ii; i < min(ii + B, N); i++)
                    for (int j = jj; j < min(jj + B, N); j++)
                        out[j][i] = in[i][j];
        printf("%d %d %d\n", out[0][1], out[4][0], out[2][3]); /* 5 4 17 */
        return 0;
    }
  6. 6

    Multiply two matrices and explain the best loop order for row-major arrays.

    medium

    The triple loop is O(N^3). Order i, k, j keeps the inner loop walking along rows of B and C, which are contiguous in row-major storage, so it is usually much faster than i, j, k, whose inner loop strides down a column of B. Results are identical for integers. Common mistake: forgetting to zero C before accumulating.

    c
    #include <stdio.h>
    #define N 2
    int main(void) {
        int A[N][N] = {{1, 2}, {3, 4}}, B[N][N] = {{5, 6}, {7, 8}}, C[N][N] = {{0}};
        for (int i = 0; i < N; i++)
            for (int k = 0; k < N; k++)
                for (int j = 0; j < N; j++)
                    C[i][j] += A[i][k] * B[k][j];
        printf("%d %d %d %d\n", C[0][0], C[0][1], C[1][0], C[1][1]); /* 19 22 43 50 */
        return 0;
    }
  7. 7

    Return the k largest elements of a stream using a min-heap.

    medium

    Keep a min-heap of size k. For each new value, push it, and if the heap grows beyond k, pop the smallest. At the end the heap holds the k largest. Time O(n log k), space O(k), better than sorting at O(n log n) when k is small. Common mistake: using a max-heap of all n elements, which costs more memory and time.

    python
    import heapq
    
    def top_k(nums, k):
        h = []
        for x in nums:
            heapq.heappush(h, x)
            if len(h) > k:
                heapq.heappop(h)
        return sorted(h, reverse=True)
    
    print(top_k([5, 1, 9, 3, 7, 8], 3))  # [9, 8, 7]
  8. 8

    Align a size up to the next multiple of a power-of-two alignment.

    easy

    For an alignment a that is a power of two, (x + a - 1) & ~(a - 1) rounds up. For x = 70 and a = 64 the result is 128; for x = 64 it stays 64. Time O(1). Common mistake: using the formula with an alignment that is not a power of two, where the mask trick is wrong, or overflowing when x is near the type's maximum.

    c
    #include <stdio.h>
    #include <stdint.h>
    uint32_t align_up(uint32_t x, uint32_t a) { return (x + a - 1) & ~(a - 1); }
    int main(void) {
        printf("%u %u %u\n", align_up(70, 64), align_up(64, 64), align_up(1, 256)); /* 128 64 256 */
        return 0;
    }
  9. 9

    Predict the output: integer division and modulo with negative operands.

    medium

    Since C99, division truncates toward zero and the remainder has the sign of the dividend, so -7 / 2 is -3 and -7 % 2 is -1, while 7 / -2 is -3 and 7 % -2 is 1. Python differs: -7 // 2 is -4 and -7 % 2 is 1. Output: -3 -1 -3 1. Common mistake: expecting floor division and a non-negative remainder in C.

    c
    #include <stdio.h>
    int main(void) {
        printf("%d %d %d %d\n", -7 / 2, -7 % 2, 7 / -2, 7 % -2);
        return 0;
    }
  10. 10

    Predict the output: floating-point equality.

    easy

    0.1 and 0.2 are not exactly representable in binary, so their sum in double precision is 0.30000000000000004 and the comparison with 0.3 is false. Output: 0. Compare with a tolerance, such as fabs(a - b) < 1e-9, or with relative error for large values. This matters for GPU code because the order of floating-point additions in a parallel reduction changes the rounding of the result.

    c
    #include <stdio.h>
    int main(void) {
        double a = 0.1 + 0.2;
        printf("%d %.17g\n", a == 0.3, a);
        return 0;
    }
  11. 11

    Merge two sorted arrays into one in linear time.

    medium

    Walk both with two indices and always copy the smaller current element; copy whatever remains of the other array at the end. Time O(n + m), space O(n + m) for the output. Use <= when comparing so equal elements keep their original order, which makes the merge stable. Common mistake: forgetting to drain the tail of the longer array.

    python
    def merge(a, b):
        i = j = 0
        out = []
        while i < len(a) and j < len(b):
            if a[i] <= b[j]:
                out.append(a[i]); i += 1
            else:
                out.append(b[j]); j += 1
        out.extend(a[i:]); out.extend(b[j:])
        return out
    
    print(merge([1, 4, 9], [2, 3, 10, 11]))  # [1, 2, 3, 4, 9, 10, 11]
  12. 12

    Count the leading zeros of a 32-bit unsigned value without a built-in.

    hard

    Binary search on the bit position: if the top 16 bits are zero add 16 and shift left by 16, then repeat with 8, 4, 2 and 1. A zero input gives 32. Time O(log w), here five steps. GPUs and CPUs have a single instruction for this (clz), and in GCC __builtin_clz(0) is undefined, so test zero first. Common mistake: looping over all 32 bits when asked for an efficient answer.

    c
    #include <stdio.h>
    #include <stdint.h>
    int clz32(uint32_t x) {
        if (x == 0) return 32;
        int n = 0;
        if ((x >> 16) == 0) { n += 16; x <<= 16; }
        if ((x >> 24) == 0) { n += 8;  x <<= 8; }
        if ((x >> 28) == 0) { n += 4;  x <<= 4; }
        if ((x >> 30) == 0) { n += 2;  x <<= 2; }
        if ((x >> 31) == 0) { n += 1; }
        return n;
    }
    int main(void) {
        printf("%d %d %d\n", clz32(1), clz32(0x00F00000u), clz32(0x80000000u)); /* 31 8 0 */
        return 0;
    }

Frequently asked questions

Will the NVIDIA coding round ask me to write CUDA?

Not necessarily. NVIDIA says technical candidates may get a coding exercise on HackerRank, a whiteboard or a laptop it provides, and the content follows the job description. Be ready for C++ or Python algorithms, and for CUDA only if the role lists it.

Which language should I use?

Use C++ if the posting asks for it, since systems and GPU roles usually do. Python is fine for pure algorithm problems if the platform allows it.

Are these real NVIDIA problems?

No. They are practice problems in the style of topics such roles commonly cover. NVIDIA does not publish its question set.

How should I explain parallel versions in an interview?

State which iterations are independent, where threads must synchronise, what the memory access pattern is, and how many steps and how much work the parallel version takes compared with the sequential one.

Sources

Related guides

More in Company Interview Questions

See all in this section