FastPrepCheck Endianness Of A Byte Array
Problems/Check Endianness Of A Byte Array

Check Endianness Of A Byte Array

NVIDIA logoNVIDIA● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asked to check endianness of a byte array. The judged core task matches the visible source at about 90%; the compared integer, little/big/neither result family, and examples are specified for practice.

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 = 1return = "little"

The least significant byte of 1 is 1 and sits at index 0.

Example 2

bytes = [0,0,0,1]value = 1return = "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.

More NVIDIA problems

  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Query a Header-Encoded MatrixOA · Seen Oct 2026
  • Maximum ScoreOA · Seen Oct 2026
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public String checkEndianness(int[] bytes, int value) {
      // Write your code here.
    }
}
Checking account…