Swap Adjacent Nibbles
Updated
Problem statement
You are given a non-negative value. Write it in hexadecimal as exactly eight digits, keeping any leading zeroes. Each hex digit stands for four bits, and a group of four bits is called a nibble.
Swap the digits two at a time: the first with the second, the third with the fourth, and so on. Read the result as an unsigned 32-bit number and return it as a long.
Function
swapAdjacentNibbles(value: long) → longExamples
Example 1
value = 305419896return = 558065031In hexadecimal, the input is 12 34 56 78. Swapping the two digits in each pair gives 21 43 65 87. That number, written in decimal, is the answer.
Constraints
0 <= value <= 2^32 - 1
More Arista Networks interview questions
- First Missing Number in a Consecutive ArrayOA · PHONE SCREEN · Seen Oct 2026
- Remove All Repeated Values from a Linked ListPHONE SCREEN · Seen Oct 2026
- Trace Nested Object Destruction OrderPHONE SCREEN · Seen Oct 2026
- Trace Pointer Rebinding and Pointee UpdatesPHONE SCREEN · Seen Oct 2026
- Unique Target-Sum Pairs in a Sorted Doubly Linked ListPHONE SCREEN · Seen Aug 2026
- Generic Stack Operation SequencePHONE SCREEN · Seen Aug 2026
- API Bandwidth AllocationOA · Seen Sep 2026
- LFU CacheOA · Seen Sep 2026
- Maximum Server Processing TimeOA · Seen Aug 2026
- Minimum Adjacent Merges to Form a PalindromeOA · Seen Aug 2026
Similar questions at other companies
- Count the 1 Bits in a 32-Bit ValueAmazon · PHONE SCREEN
- Find the Unique Element Among PairsChubb · PHONE SCREEN
- XOR Pseudorandom SequenceBaseten · PHONE SCREEN
- Maximize Binary XOR with a Set-Bit LimitJP Morgan Chase · PHONE SCREEN
- The One Repeated NumberAdobe · PHONE SCREEN
- CPU Register Bitwise OperationsHeadlands Technologies · PHONE SCREEN
- Integer to Binary RepresentationThe Walt Disney Company · PHONE SCREEN
- Spelling Bee Word FilterBloomberg LP · PHONE SCREEN
- Find the Element With Odd FrequencyZscaler · PHONE SCREEN
- Longest Consecutive One Bits in a 32-Bit IntegerGoogle · PHONE SCREEN