Check Endianness Of A Byte Array
Reported by candidates from Nvidia's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Nvidia OA reported in September 2026 has a byte-array question that looks like a freebie, and the edge cases are where people lose it. You get up to four bytes and a value, and you decide if the array is little-endian, big-endian, or neither. Palindromic arrays, one-byte inputs and values too big for the width all hit the same tie-break rule. It's a plain array problem with no clever data structure. If you blank on the tie-break during the live assessment, StealthCoder is the quiet safety net that reads the prompt and hands you a clean solution.
The problem
You are given an integer array bytes whose values are unsigned 8-bit quantities in [0, 255], and a non-negative integer value. Interpret bytes as a fixed-width encoding of value using exactly bytes.length bytes. Return "little" if bytes is the little-endian encoding of value (least significant byte at index 0). Return "big" if bytes is the big-endian encoding of value (most significant byte at index 0). Return "neither" if value does not fit in that many bytes or neither encoding matches. When both encodings are identical, including every one-byte input, return "little". Function checkEndianness(bytes: int[], value: int) → String Examples Example 1 bytes = [1,0,0,0] value = 1 return = "little" The least significant byte of 1 is 1 and sits at index 0. Example 2 bytes = [0,0,0,1] value = 1 return = "big" The least significant byte of 1 sits at the last index, which is big-endian. Constraints 1 <= bytes.length <= 4. 0 <= bytes[i] <= 255. 0 <= value <= 2^31 - 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to stop thinking about bit tricks and just build both encodings. For little, loop i from 0 to n-1 and check that bytes[i] equals (value >> (8*i)) & 255. For big, check that bytes[i] equals (value >> (8*(n-1-i))) & 255. Then you need the overflow check: if value >= 2^(8*n), neither encoding can match, so return neither. Watch the order. Test little first, because the spec says ties go to little. That covers every one-byte input and symmetric arrays like [0,0,0,0] or [5,5]. The common pitfall is testing big first and returning the wrong label on a tie. The other one is forgetting that a high byte silently dropped by masking can fake a match when value is too large. Use a width check or compare the full reconstructed value. If you freeze mid-assessment, StealthCoder is the hedge that gets you the working version fast.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Check Endianness Of A Byte Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Nvidia's OA.
Nvidia reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Check Endianness Of A Byte Array FAQ
How hard is the Nvidia endianness question really?+
Easy on algorithm, tricky on details. Length is at most 4, so there's no performance concern. The points are lost on the tie-break rule and the value-too-large case. If you handle those two deliberately, it's a ten-minute problem.
What's the trick to checking little versus big endian?+
Extract each byte of value with a shift and a mask of 255. Compare against bytes in forward order for little and reverse order for big. Check little first so ties return little. That's the whole solution, plus an overflow guard.
How do I handle a value that doesn't fit in the array?+
Compute whether value is at least 2 to the power of 8 times the length. If so, return neither immediately. Without this, masking can drop high bits and give you a false match. Values go up to 2^31 - 1, so a one-byte array with value 300 must return neither.
Which edge cases should I test before submitting?+
Test a single byte like [7] with value 7, which must return little. Test a symmetric array such as [0,0] with value 0, also little. Test [0,0,0,1] with value 1 for big. Test [1,0] with value 256 for neither, and a value that is too large for the width.
Can I prepare for this in 48 hours?+
Yes. Practice bit shifting and masking to pull bytes out of an integer, and write both comparisons by hand once. Then rehearse the tie-break order. This is a fundamentals question, so a short refresher on shifts is enough.