← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Oracle SWE coding round, one array problem that looks easy until you start thinking about edge cases. Walked away feeling okay about it but not great.

Questions Asked (1)

Q1

Given an integer array and an integer k, count the number of unique pairs in the array where the absolute difference between the two elements equals k.

Algorithms & Data Structures
Author's notes

The k == 0 case is what gets people.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: whether pairs are index-based or value-based, and if duplicates count as unique pairs. Then propose an efficient solution using a hash set to track seen elements, achieving O(n) time and O(n) space, and discuss edge cases like k=0 and negative k.

Pro tip: Mention that for k=0, you need to count pairs of identical elements, which requires a frequency map instead of a set. Also, note that if k<0, the answer is 0 since absolute difference is non-negative.

1. Clarify the problem

Ask whether pairs are based on indices or values, and whether duplicate values count as unique pairs. Confirm that k is non-negative.

2. Choose the right data structure

Use a hash set for k>0 to track seen elements, or a frequency map for k=0 to count duplicates. Explain why a set is efficient for O(1) lookups.

3. Outline the algorithm

For k>0: iterate through the array, for each element check if element+k or element-k is in the set, and if so, increment count; then add the element to the set. For k=0: count frequencies and add freq*(freq-1)/2 for each element with freq>1.

4. Analyze complexity

State that the time complexity is O(n) and space complexity is O(n) in the worst case. Compare with the brute-force O(n^2) approach to highlight efficiency.

5. Handle edge cases

Discuss cases like empty array, k<0 (return 0), k=0 (use frequency map), and arrays with many duplicates. Also mention that if k is very large, the set may not help but still O(n).

Key Points to Mention

  • Clarify whether pairs are index-based or value-based, and if duplicates count as unique pairs.
  • Use a hash set for O(n) time complexity when k>0, and a frequency map when k=0.
  • For k>0, check both element+k and element-k to avoid missing pairs, but ensure each pair is counted once.
  • For k=0, count pairs of identical elements using combinations: freq*(freq-1)/2.
  • Edge cases: k<0 returns 0, empty array returns 0, and k=0 requires special handling.
  • Compare with brute-force O(n^2) to demonstrate awareness of efficiency.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.