FastPrepDigit-Reversed Pairs in an Array
Problems/Digit-Reversed Pairs in an Array

Digit-Reversed Pairs in an Array

Expedia logoExpedia● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One post, published on September 8, 2018 by a student from an Expedia campus internship drive, lists this task in an interview after the online test.

The post shows one example list of seven numbers with its three pairs and says the answer is the number of such pairs plus the pairs themselves. It gives no limits and no rule for repeated numbers or for the order of the pairs. One example pair puts 1 with 1000, which plain digit reversal does not give. Here, a number's reverse is its digits written backwards with leading zeros dropped, so 1000 reverses to 1. Two positions form a pair when either number is the reverse of the other. A palindrome pairs with another copy of itself. The function returns one row per pair of positions, written as [smaller, larger] and sorted, so the count is the number of rows. There are 1 to 2000 numbers from 1 to 2147483647. Only the returned rows are checked, not the time.

Our version is about 70% the same as the reported question.

You are given an array nums of positive integers. The reverse of a number is its decimal digits written backwards, with any leading zeros dropped. For example, the reverse of 305 is 503, and the reverse of 1000 is 1.

Two different positions i < j form a pair when nums[i] is the reverse of nums[j] or nums[j] is the reverse of nums[i]. A number that reads the same backwards, such as 11, pairs with another position that holds the same value.

Return every pair as a row [smaller, larger] of its two values, one row for each pair of positions, so repeated numbers give repeated rows. Sort the rows in ascending order, comparing the first value and then the second. The number of pairs is the number of rows.

If there is no pair, return an empty list.

Function

digitReversePairs(nums: int[]) → int[][]

Examples

Example 1

nums = [12,21,5,305,503,7]return = [[12,21],[305,503]]

The digits of 12 read backwards give 21, so positions 0 and 1 form a pair. The digits of 305 read backwards give 503, so positions 3 and 4 form a pair. The numbers 5 and 7 are not reverses of anything else in the list. The pairs are listed from the smaller number to the larger one and sorted, so the answer is [[12, 21], [305, 503]], which is 2 pairs.

Example 2

nums = [20,2,4,4]return = [[2,20],[4,4]]

Reading 20 backwards gives 02, and with the leading zero dropped this is 2, so 20 and 2 form a pair. The two copies of 4 read the same backwards, so they are a pair of two different positions. There are 2 pairs: [[2, 20], [4, 4]].

Example 3

nums = [10,100,5]return = []

Both 10 and 100 read backwards as 1, but neither one is the reverse of the other, and 5 has no partner. So there are no pairs and the answer is the empty list.

Constraints

  • 1 <= nums.length <= 2000
  • 1 <= nums[i] <= 2147483647 (every value fits in a 32-bit signed integer).

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
  • Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
  • Equation Tuple CombinationZoox · ONSITE INTERVIEW
  • Unique Near-Equal Target-Sum PairsFivetran · ONSITE INTERVIEWFivetran interview questions
  • Minimum Unique Card Suffix LengthBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Pairs Divisible by KApple · ONSITE INTERVIEWApple interview questions
  • Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Majority ElementMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Index Pairs with Equal Value OffsetGoogle · ONSITE INTERVIEWGoogle interview questions
  • Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int[][] digitReversePairs(int[] nums) {
        // Write your code here.
    }
}
Checking account…