KPIT coding round questions
Last updated 2026-11-19
KPIT is known for automotive software: ECU code, diagnostics, AUTOSAR stacks, electrification and driver-assistance features. Candidates commonly describe a test of aptitude, technical questions and basic programming, with C prominent for embedded profiles. KPIT has not published a syllabus we can cite, so this set is practice shaped by the vehicle domain and not a preview of any real paper.
Its twelve problems all happen on a CAN network or inside an ECU: pulling a signal out of an eight-byte frame, checking a CRC, queuing received frames, spotting lost messages after a counter wraps. Every routine was compiled with gcc and executed on sample data. For the conversational side of the process, read KPIT interview questions.
| Round style (commonly reported) | Aptitude, technical MCQs and basic coding, often in C |
|---|---|
| Practice difficulty | Easy to medium, with a couple of harder CAN items |
| Code shown | C, compiled and run with gcc |
A CAN frame in thirty seconds
A classic CAN frame carries an identifier and up to eight data bytes. Lower identifiers win bus arbitration. Engineers describe what lives in the data bytes with signals: a start bit, a length, a byte order, a scale factor and an offset. Almost every task in vehicle software, from displaying vehicle speed to reading a fault flag, begins with extracting such a signal correctly.
Two byte orders exist. Intel (little-endian) signals count their start bit as the least significant bit and grow towards higher bits. Motorola (big-endian) signals give the most significant bit and snake across bytes. Knowing which one a question uses is half the answer.
What embedded reviewers look for
- Fixed-width types, with no reliance on int being a particular size.
- No dynamic memory and no recursion in anything that could run in an interrupt.
- Interrupt-safe sharing: one writer per index and volatile where hardware or an ISR touches the data.
- Counter and timer arithmetic that survives wrap-around.
- Clear handling of full, empty and malformed input.
Related reading
Bit-level basics are in bit manipulation interview questions, and general firmware topics in embedded systems interview questions.
Hiring status
We have no sourced KPIT statement on fresher numbers, dates or eligibility and quote none. See your invitation and KPIT's careers pages.
KPIT coding round questions: questions with worked answers
1 Extract an Intel-format (little-endian) signal of up to 32 bits from an eight-byte CAN payload, given its start bit and length.
mediumAssemble the eight bytes into a 64-bit integer with byte zero as the lowest byte, shift right by the start bit and mask to the length. Constant time. Using a 32-bit accumulator loses signals that straddle the middle of the frame. Building the mask with 1 << len is undefined when len reaches the type width, so build it from a 64-bit constant and keep length at 32 or below.
c#include <stdint.h> uint32_t get_intel(const uint8_t d[8], unsigned start, unsigned len) { uint64_t raw = 0; for (int i = 7; i >= 0; i--) raw = (raw << 8) | d[i]; raw >>= start; raw &= (1ULL << len) - 1ULL; return (uint32_t)raw; }2 Extract a Motorola-format (big-endian) signal given the position of its most significant bit and its length, using the usual numbering where bit 7 of byte 0 is position 7.
hardRead bit by bit from the most significant end. Take the bit at the current position, append it to the result, then move to the next lower bit; after bit 0 of a byte, jump to bit 7 of the next byte, which is an advance of 15 positions. O(len) time. Many people reuse the Intel routine with reversed bytes and get signals that cross byte boundaries wrong.
c#include <stdint.h> uint32_t get_motorola(const uint8_t d[8], unsigned start_msb, unsigned len) { uint32_t v = 0; unsigned pos = start_msb; for (unsigned i = 0; i < len; i++) { unsigned byte = pos / 8, off = pos % 8; v = (v << 1) | ((d[byte] >> off) & 1u); pos = (off == 0) ? pos + 15 : pos - 1; } return v; }3 A signal's physical value is raw x factor + offset. Convert a raw value to thousandths of a unit using integer arithmetic only, for example engine coolant temperature = raw x 0.5 - 40.
easyExpress factor and offset as integers in thousandths (500 and -40000), multiply in 64 bits so a large raw value cannot overflow, add the offset, and return milli-units. Constant time. For raw 130 the result is 25000, meaning 25.0 degrees Celsius. Converting to float and back wastes cycles and introduces rounding error that a calibration engineer will notice.
c#include <stdint.h> int32_t to_milli(uint32_t raw, int32_t factor_milli, int32_t offset_milli) { return (int32_t)((int64_t)raw * factor_milli + offset_milli); }4 Implement CRC-8 as used in the SAE J1850 style: polynomial 0x1D, initial value 0xFF and final XOR 0xFF, over a byte buffer.
mediumBitwise shift register. XOR each byte into the register, then eight times shift left, XORing with 0x1D whenever the top bit was set. Apply the final XOR at the end. O(8n). The check value for the ASCII text 123456789 is 0x4B. A table-driven version trades 256 bytes of flash for speed. The typical errors are forgetting the initial or final value and testing the bit after the shift rather than before.
c#include <stdint.h> #include <stddef.h> uint8_t crc8_j1850(const uint8_t *d, size_t n) { uint8_t c = 0xFF; for (size_t i = 0; i < n; i++) { c ^= d[i]; for (int b = 0; b < 8; b++) c = (c & 0x80u) ? (uint8_t)((c << 1) ^ 0x1Du) : (uint8_t)(c << 1); } return (uint8_t)(c ^ 0xFFu); }5 Design a receive queue for CAN frames filled by an interrupt handler and drained by the main loop, using a fixed array, with no locks.
hardSingle-producer single-consumer ring. Use a power-of-two capacity and free-running head and tail counters; the slot is index masked with size - 1, the queue is full when head minus tail equals the size and empty when they are equal. The ISR only writes head and the loop only writes tail, so no lock is needed on a single core. O(1) operations. Mark the indices volatile, and on cores with write buffers add a barrier between storing the frame and publishing head.
c#include <stdint.h> #include <stdbool.h> #define RXQ_SIZE 16u typedef struct { uint32_t id; uint8_t dlc; uint8_t data[8]; } can_frame_t; typedef struct { can_frame_t slot[RXQ_SIZE]; volatile uint32_t head; volatile uint32_t tail; } rxq_t; bool rxq_push(rxq_t *q, const can_frame_t *f) { if (q->head - q->tail == RXQ_SIZE) return false; q->slot[q->head & (RXQ_SIZE - 1u)] = *f; q->head++; return true; } bool rxq_pop(rxq_t *q, can_frame_t *f) { if (q->head == q->tail) return false; *f = q->slot[q->tail & (RXQ_SIZE - 1u)]; q->tail++; return true; }6 A transmitter adds a 4-bit rolling counter (0 to 15) to every message. Given the previous and current counter values, how many frames were lost in between?
easyModular difference. The expected next value is previous plus one, so lost frames equal (current - previous - 1) modulo 16, which a mask of 0x0F gives for free even when the counter wraps from 15 to 0. Constant time. A result of zero means consecutive. A value repeated exactly is reported as 15 lost, so real code checks for a duplicate separately. Plain subtraction without the mask goes negative at the wrap.
c#include <stdint.h> unsigned frames_lost(uint8_t prev, uint8_t cur) { return (unsigned)((cur - prev - 1) & 0x0F); }7 Return the index of the highest set bit of a 32-bit value, such as the highest-priority active request, or -1 for zero.
mediumBinary search on the width. If the value has any bit in the top half, move it down by 16 and add 16 to the index; repeat with 8, 4 and 2, then add one more if the remaining value is at least 2. Five steps and no loop over all 32 bits. Looping with a right shift also works. Comparing with the unsigned literal 1u << 16, and not with a signed constant, avoids a sign-conversion surprise.
c#include <stdint.h> int msb_index(uint32_t x) { if (x == 0) return -1; int n = 0; if (x >= (1u << 16)) { x >>= 16; n += 16; } if (x >= (1u << 8)) { x >>= 8; n += 8; } if (x >= (1u << 4)) { x >>= 4; n += 4; } if (x >= (1u << 2)) { x >>= 2; n += 2; } if (x >= 2u) { n += 1; } return n; }8 Compute vehicle speed in tenths of km/h from wheel pulses counted in an interval, given pulses per revolution, tyre circumference in millimetres and the interval in milliseconds.
mediumDistance over time. Distance in millimetres is pulses divided by pulses-per-revolution times circumference; millimetres per millisecond equals metres per second, and multiplying by 3.6 gives km/h, so tenths of km/h need a factor of 36. Multiply everything first in 64 bits, then divide once. Example: 100 pulses, 50 per revolution, 2000 mm, 1000 ms gives 144, which is 14.4 km/h. Dividing early throws away resolution at low speed.
c#include <stdint.h> uint32_t speed_x10(uint32_t pulses, uint32_t ppr, uint32_t circ_mm, uint32_t ms) { if (ppr == 0 || ms == 0) return 0; uint64_t num = (uint64_t)pulses * circ_mm * 36u; uint64_t den = (uint64_t)ppr * ms; return (uint32_t)(num / den); }9 Simulate CAN arbitration for up to 32 nodes that start sending 11-bit identifiers together. Return the identifier that wins the bus.
hardWalk the identifier bits from the most significant. A 0 is dominant: if any node still contending sends a 0 at this bit, every contender sending a 1 drops out. After bit 0 the survivor holds the lowest identifier. O(11 x nodes). The result equals the minimum, but writing the simulation shows you understand why. Treating 1 as dominant reverses the outcome, and identical IDs from two nodes would be a bus error in reality.
c#include <stdint.h> #include <stddef.h> #include <stdbool.h> uint16_t arbitrate(const uint16_t *ids, size_t n) { bool alive[32]; if (n == 0 || n > 32) return 0xFFFF; for (size_t i = 0; i < n; i++) alive[i] = true; for (int bit = 10; bit >= 0; bit--) { bool dominant = false; for (size_t i = 0; i < n; i++) if (alive[i] && !((ids[i] >> bit) & 1u)) dominant = true; if (!dominant) continue; for (size_t i = 0; i < n; i++) if (alive[i] && ((ids[i] >> bit) & 1u)) alive[i] = false; } for (size_t i = 0; i < n; i++) if (alive[i]) return ids[i]; return 0xFFFF; }10 A free-running 32-bit millisecond tick overflows after about 49 days. Write a timeout test and an ordering test that stay correct across the wrap.
mediumUse unsigned subtraction. The elapsed time is now - start computed in uint32_t, which is right even after the counter wraps, as long as the real interval is under half the range. Comparing now >= start + timeout fails because the sum itself can wrap. For ordering, cast the difference to a signed 32-bit value and test for negative. Constant time. The signed cast is implementation-defined in the standard but behaves as expected on common compilers.
c#include <stdint.h> #include <stdbool.h> bool timed_out(uint32_t now, uint32_t start, uint32_t timeout) { return (uint32_t)(now - start) >= timeout; } bool tick_before(uint32_t a, uint32_t b) { return (int32_t)(a - b) < 0; }11 Turn a stream of 16-bit sensor readings into an on/off signal with hysteresis: switch on at or above a high threshold, off at or below a low threshold, otherwise hold the previous state.
easySchmitt-trigger logic. Keep one state variable; set it to 1 when the reading reaches the high threshold, to 0 when it falls to the low threshold, and leave it unchanged in between. O(n) time, O(1) extra state. This stops a signal hovering near one threshold from chattering. Using a single threshold removes the dead band and causes the flicker the design is supposed to avoid. Require low to be below high.
c#include <stdint.h> #include <stddef.h> void schmitt(const int16_t *in, uint8_t *out, size_t n, int16_t low, int16_t high, uint8_t init) { uint8_t s = init ? 1u : 0u; for (size_t i = 0; i < n; i++) { if (in[i] >= high) s = 1u; else if (in[i] <= low) s = 0u; out[i] = s; } }12 A message struct holds a uint8_t, a uint32_t, another uint8_t and a uint16_t in that order. What is its size on a typical 32-bit or 64-bit compiler, and how do you shrink it without packing?
mediumPadding follows alignment. The 32-bit member must sit on a 4-byte boundary, so the first byte is followed by three padding bytes, and the struct is padded at the end to a multiple of its largest alignment; the original layout takes 12 bytes. Ordering members from largest to smallest gives 8 bytes with no wasted space. Use offsetof to check. Packing the struct removes padding but creates unaligned accesses, which some ARM cores fault on.
c#include <stdint.h> #include <stddef.h> struct msg_loose { uint8_t a; uint32_t b; uint8_t c; uint16_t d; }; struct msg_tight { uint32_t b; uint16_t d; uint8_t a; uint8_t c; }; _Static_assert(sizeof(struct msg_loose) == 12, "loose layout"); _Static_assert(sizeof(struct msg_tight) == 8, "tight layout"); _Static_assert(offsetof(struct msg_loose, b) == 4, "b offset");
Frequently asked questions
Do I need to know CAN before a KPIT coding round?
Basic familiarity helps for embedded profiles, but a coding question should describe any protocol detail it needs. The bit-handling skills behind CAN are the real preparation.
Intel or Motorola, which byte order is more common?
Both are used in vehicle databases. Always read which order the question states and never assume it.
Why is volatile mentioned in the ring buffer answer?
It stops the compiler caching an index that an interrupt handler changes. It does not make the queue atomic, which is why the design keeps one writer per index.
Can I solve these in Python or Java instead?
Python or Java can express the logic, but embedded roles tend to expect C. Practise in C first and port afterwards.
Where do I find the real KPIT selection details?
On KPIT's careers pages and in the email sent to you. This page carries no dates, headcounts or cutoffs.
Related guides
More in Company Interview Questions
- KPIT interview questions and answers
- KPMG coding round questions
- KPMG interview questions and answers
- L&T Technology Services interview questions
- LatentView Analytics Interview Questions with Answers
- LatentView Coding Round Questions
- LinkedIn Coding Round Questions With Solutions
- LinkedIn Interview Questions and Answers
- Lowe's Coding Round Questions
- Lowe's Interview Questions with Answers
- LTIMindtree Coding Round Questions with Solutions
- LTIMindtree Interview Questions for Freshers