Interview question three arrays and ONN
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
The Problem: Interview Question on Arrays and Complexity
In the world of coding interviews, problem-solving skills are tested through a variety of questions ranging from data structures to algorithms. One interesting problem involves three arrays and the computational complexity of . This type of problem challenges a candidate's understanding of algorithm efficiency and data manipulation techniques.
Problem Statement
Given three integer arrays `A`, `B`, and `C`, each containing `N` elements, the task might require you to find a specific condition or pattern among the arrays with an overall time complexity of . While the exact condition can vary depending on the interview, a common question involves determining whether there exist indices , , and such that:
This involves checking each combination of elements from the first two arrays to see if their sum is present in the third array.
Approach and Explanation
To solve this problem efficiently, especially within the constraint, you can follow a systematic approach:
- Nested Loop Search:
- Use two nested loops to iterate over all possible pairs of elements from arrays `A` and `B`.
- Compute the sum of each pair.
- Use a `Hash` Set for Quick Lookup:
- Insert all elements of array `C` into a hash set for average lookup time.
- For each computed sum from arrays `A` and `B`, check if this sum exists in the hash set.
- Terminate Early:
- Optionally, if the question allows terminating as soon as a condition is met (such as finding the first valid pair), you can exit early to save computation.
Pseudocode
Here’s a simple pseudocode to illustrate the above approach:
- Building the `Hash` Set: Inserting `N` elements of `C` into a hash set takes time.
- Nested Loops: There are two nested loops over arrays of size `N`, resulting in pairs being checked.
- Hash Set Lookup: Each lookup is on average, owing to the hash set's properties.
- Edge Cases:
- Arrays containing negative numbers, zeroes, or elements such that the equation results in edge cases like overflow.
- Arrays of differing lengths (if applicable during follow-up questions).
- Alternative Approaches: Discuss different methods if constraints were different, such as using sorting and binary search to reduce the complexity.
- Complexity Trade-offs: Discuss situations where reducing time complexity may increase space complexity and vice versa.
Related reading
- interviewstreet median challenge
- Intro to Algorithms chapter 1-1
- Introduction to Algorithm, Exercise 10.2-4
- Intuitive explanation for why QuickSort is n log n?
- Invalid Argument Error / Graph Execution Error
- InvalidArgumentError Mismatch between the current graph and the graph from the checkpoint
- IntPtr, SafeHandle and HandleRef - Explained
- IOPS vs Throughput. Which one to use while choosing AWS EBS

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.