Autocoder

Cyient coding round questions

Last updated 2026-11-19

Cyient is an engineering and technology services company with a long record in aerospace, rail, utilities, communications and geospatial work. Candidates for software and embedded profiles commonly mention an assessment that pairs aptitude with technical questions and a basic programming section. Cyient has not published a syllabus that we can cite, so this page is a practice set shaped by the company's domains, and it is not a preview of any real test.

The eleven problems are in C and use the kind of data that flows through those industries: GPS sentences, smart-meter readings, shaft encoders and telemetry streams. Each was compiled with gcc and run on sample input, and each answer says what it costs and where it usually goes wrong. For spoken rounds, see Cyient interview questions.

Round style (commonly reported)Aptitude, technical questions and basic programming
Practice difficultyEasy to medium
Code shownC, compiled and run with gcc

Where Cyient's domains meet the keyboard

Position fixes arrive as text, meters report counters, an aircraft or train sensor produces a stream that must be cleaned and compressed before storage. Short C programs over this kind of data are a natural way to check that a candidate can handle strings, integers of a known width and arrays without the safety net of a high-level language.

None of the answers here call a heavy library. Parsing is done character by character, scaling is done with integers, and every function takes the buffer length so that it cannot write past the end.

Integer maths in place of floating point

Small controllers often lack a floating-point unit, so engineering code stores a scaled integer instead: microdegrees for a coordinate, a Q15 fraction for a gain, a Q8.8 value for a temperature. The skill being tested is choosing the scale, widening before multiplying, and rounding deliberately. Two of the problems below practise exactly this, with the third in the same family covering the parsing that feeds them.

More revision material

If any C basics feel shaky, go through C programming interview questions first. For array-style practice in other languages, see array interview questions.

Hiring status

This site holds no sourced Cyient statement on fresher numbers, dates or eligibility, so none are given. Check the invitation and Cyient's careers site for the real pattern.

Cyient coding round questions: questions with worked answers

  1. 1

    Convert a GPS latitude in NMEA form ddmm.mmmm plus a hemisphere letter into signed microdegrees using integers only. For example 4916.45 N is 49.274166 degrees.

    medium

    Split degrees from minutes, then scale. The first two characters are whole degrees, the next two whole minutes, and the digits after the point are a fraction of a minute. Treat the minutes as an integer scaled by a power of ten, and convert with minutes x 1,000,000 / (60 x scale) in 64-bit arithmetic. O(length). Longitudes have three degree digits, so reusing this offset for them is a common bug. Truncation here costs under one microdegree.

    c
    #include <stdint.h>
    
    int32_t nmea_lat_to_udeg(const char *s, char hemi)
    {
        int32_t deg = (s[0] - '0') * 10 + (s[1] - '0');
        int32_t min = (s[2] - '0') * 10 + (s[3] - '0');
        int64_t frac = 0, scale = 1;
        const char *p = s + 4;
        if (*p == '.') p++;
        while (*p >= '0' && *p <= '9' && scale < 1000000) {
            frac = frac * 10 + (*p - '0');
            scale *= 10;
            p++;
        }
        int64_t min_scaled = (int64_t)min * scale + frac;
        int64_t udeg = (int64_t)deg * 1000000 + min_scaled * 1000000 / (60 * scale);
        return (int32_t)(hemi == 'S' ? -udeg : udeg);
    }
  2. 2

    Compute the checksum of an NMEA sentence: the XOR of every character between the leading $ and the asterisk.

    easy

    Fold characters with XOR. Skip the dollar sign, XOR each byte until the asterisk or the end of the string, and return the byte, which is normally printed as two hexadecimal digits. O(n). For the sentence GPGLL,4916.45,N,12311.12,W,225444,A, the value is 0x31. Including the dollar sign or the asterisk in the fold is the typical mistake, and comparing against the received hex text without parsing it makes upper and lower case disagree.

    c
    #include <stdint.h>
    
    uint8_t nmea_checksum(const char *s)
    {
        uint8_t c = 0;
        if (*s == '$') s++;
        while (*s != '\0' && *s != '*')
            c ^= (uint8_t)*s++;
        return c;
    }
  3. 3

    Multiply two Q15 fixed-point numbers (int16_t values representing -1.0 to just under 1.0) with rounding and saturation.

    medium

    Widen to 32 bits, multiply, add half a unit in the last place (1 << 14) for rounding, shift right by 15, and clamp. The only input pair that overflows is -32768 times -32768, which would give +1.0 and has to saturate to 32767. Constant time. Skipping the widening makes the product overflow 16 bits at once. Note that right-shifting a negative value is arithmetic on gcc but implementation-defined in the standard.

    c
    #include <stdint.h>
    
    int16_t q15_mul(int16_t a, int16_t b)
    {
        int32_t p = ((int32_t)a * b + (1 << 14)) >> 15;
        if (p > 32767)  p = 32767;
        if (p < -32768) p = -32768;
        return (int16_t)p;
    }
  4. 4

    A temperature is stored as a signed Q8.8 value (eight integer bits, eight fraction bits). Format it as text with two decimal places without using floating point.

    medium

    Separate sign, whole part and fraction. Work with the absolute value in 32 bits, take the whole part as value >> 8, and the fraction as the low byte scaled by 100 and rounded. Rounding can produce 100 for fractions near one, so carry into the whole part. Constant time. The negative-zero case, such as -0.001, should still print a minus sign only if the rounded result is not zero, which this version leaves as a documented simplification.

    c
    #include <stdint.h>
    #include <stdio.h>
    
    void q8_8_to_text(int16_t v, char *out, size_t cap)
    {
        int32_t a = v < 0 ? -(int32_t)v : v;
        int32_t whole = a >> 8;
        int32_t frac = (((a & 0xFF) * 100) + 128) >> 8;
        if (frac == 100) { whole++; frac = 0; }
        snprintf(out, cap, "%s%d.%02d", v < 0 ? "-" : "", (int)whole, (int)frac);
    }
  5. 5

    A 32-bit register holds pending interrupt flags. Return the number of the lowest pending interrupt and clear that flag, or -1 if none is pending.

    medium

    Isolate then clear. The expression x & (~x + 1) keeps only the lowest set bit, and x & (x - 1) clears it. Count how far the isolated bit sits from bit zero by shifting. At most 32 iterations, constant space. On real hardware read the register once into a local copy first, because the flags can change between two reads. Using a signed int for the register invites undefined behaviour on the top bit.

    c
    #include <stdint.h>
    
    int pop_irq(uint32_t *pending)
    {
        uint32_t p = *pending;
        if (p == 0) return -1;
        uint32_t low = p & (~p + 1u);
        *pending = p & (p - 1u);
        int n = 0;
        while (!(low & 1u)) {
            low >>= 1;
            n++;
        }
        return n;
    }
  6. 6

    A rotary shaft encoder outputs Gray code. Write functions to convert a 16-bit binary angle to Gray and back.

    medium

    Binary to Gray is b XOR (b >> 1), so neighbouring positions differ in one bit. The inverse XORs the value with all of its right shifts: starting from g >> 1, keep folding while the shift is non-zero. Both run in O(16) at most. Gray code is used so a misread at a transition is off by one step instead of a wild jump. Decoding by XORing only once is wrong for values wider than two bits.

    c
    #include <stdint.h>
    
    uint16_t to_gray(uint16_t b)
    {
        return (uint16_t)(b ^ (b >> 1));
    }
    
    uint16_t from_gray(uint16_t g)
    {
        for (uint16_t s = (uint16_t)(g >> 1); s != 0; s >>= 1)
            g ^= s;
        return g;
    }
  7. 7

    Count the strict local peaks in an array of 16-bit vibration readings: interior samples larger than both neighbours.

    easy

    Single scan over interior indices. Compare each sample with the one before and after. O(n) time, O(1) space. Write the loop condition as i + 1 < n rather than i < n - 1, because with an unsigned size the subtraction wraps when n is zero. Flat tops, where two equal samples form a plateau, are not counted by a strict test, and the statement should say whether they are.

    c
    #include <stdint.h>
    #include <stddef.h>
    
    size_t count_peaks(const int16_t *a, size_t n)
    {
        size_t c = 0;
        for (size_t i = 1; i + 1 < n; i++) {
            if (a[i] > a[i - 1] && a[i] > a[i + 1])
                c++;
        }
        return c;
    }
  8. 8

    Run-length encode a byte buffer into (count, value) pairs written into a caller-supplied output buffer, returning the output length or an error if the buffer is too small.

    medium

    Scan runs and write pairs. Count equal bytes up to 255 so the count fits in one byte, check the remaining capacity before writing, and return a sentinel such as SIZE_MAX on overflow. O(n) time. Worst-case output is twice the input when no neighbours match, which is why the capacity check matters. Writing first and checking later overruns the buffer, and counting past 255 truncates silently.

    c
    #include <stdint.h>
    #include <stddef.h>
    
    size_t rle_encode(const uint8_t *in, size_t n, uint8_t *out, size_t cap)
    {
        size_t o = 0;
        for (size_t i = 0; i < n; ) {
            uint8_t v = in[i];
            size_t run = 1;
            while (i + run < n && in[i + run] == v && run < 255)
                run++;
            if (o + 2 > cap) return SIZE_MAX;
            out[o++] = (uint8_t)run;
            out[o++] = v;
            i += run;
        }
        return o;
    }
  9. 9

    A sorted table of 32-bit altitude thresholds is stored in flash. Return the index of the first entry that is not less than a key, or n if all are smaller.

    easy

    Lower-bound binary search with a half-open range [lo, hi). Compare the middle element; if it is less than the key move lo past it, otherwise pull hi down to it. O(log n) time, O(1) space. Computing the middle as lo + (hi - lo) / 2 avoids overflow. Using a closed range with hi = n - 1 breaks on an empty table, and returning when an equal element is found misses earlier duplicates.

    c
    #include <stdint.h>
    #include <stddef.h>
    
    size_t lower_bound(const int32_t *a, size_t n, int32_t key)
    {
        size_t lo = 0, hi = n;
        while (lo < hi) {
            size_t mid = lo + (hi - lo) / 2;
            if (a[mid] < key) lo = mid + 1;
            else              hi = mid;
        }
        return lo;
    }
  10. 10

    A rows x cols grid of tile readings arrives as a flat array in row-major order. Return the sum of its border cells, each counted once.

    medium

    Index arithmetic on a flat array. Cell (r, c) lives at r x cols + c. Add the entire first and last rows, then for each middle row add only its first and last cells. Guard the single-row and single-column cases so nothing is counted twice. O(rows + cols) time. Treating the flat array as a pointer to pointers is a frequent mistake, and so is computing the product in int when the grid is large.

    c
    #include <stddef.h>
    
    long border_sum(const int *m, size_t rows, size_t cols)
    {
        if (rows == 0 || cols == 0) return 0;
        long s = 0;
        for (size_t j = 0; j < cols; j++) {
            s += m[j];
            if (rows > 1) s += m[(rows - 1) * cols + j];
        }
        for (size_t i = 1; i + 1 < rows; i++) {
            s += m[i * cols];
            if (cols > 1) s += m[i * cols + cols - 1];
        }
        return s;
    }
  11. 11

    Remove repeated consecutive values from a sorted array of 32-bit meter readings in place and return the new length.

    easy

    Write index trails read index. Copy a reading forward only when it differs from the last one kept. O(n) time, O(1) space, and the surviving values stay in order. Starting the write index at one, after handling the empty array, keeps the first element. Comparing a[r] with a[r - 1] after earlier writes have already overwritten that slot reads the wrong value, so compare against the last kept element.

    c
    #include <stdint.h>
    #include <stddef.h>
    
    size_t squeeze_sorted(int32_t *a, size_t n)
    {
        if (n == 0) return 0;
        size_t w = 1;
        for (size_t r = 1; r < n; r++) {
            if (a[r] != a[w - 1])
                a[w++] = a[r];
        }
        return w;
    }

Frequently asked questions

Does Cyient test C for every role?

Reports suggest embedded and engineering roles lean on C or C++, while other profiles may use a general-purpose language. Your invitation states the languages allowed.

Why avoid floating point in these answers?

Many microcontrollers have no floating-point unit, so scaled integers are faster and more predictable. It also shows you can reason about range and rounding.

What should I check first in a C solution?

The integer widths, the loop bounds with unsigned sizes, and whether any write can run past a buffer. Those three catch most failing cases.

Are the NMEA examples likely to appear in a test?

They are practice problems in the spirit of Cyient's geospatial and avionics work, not a prediction. The underlying skills, string parsing and fixed-point scaling, are widely useful.

Where is the official Cyient process described?

On Cyient's careers pages and in the email you receive. This page quotes no dates, numbers or cutoffs.

Related guides

More in Company Interview Questions

See all in this section