Count Numbers Not Equal to the First Two
Updated
Problem statement
Given an array of integers numbers, count all numbers that are not equal to numbers[0] or numbers[1], if they exist in the array.
Array indices are 0-based. If numbers has only one element, numbers[1] does not exist, so count the numbers that are different from numbers[0].
Note: You do not need the most optimal solution. A solution that runs in O(numbers.length^2) time is fast enough.
Function
solution(numbers: int[]) → intExamples
Example 1
numbers = [4,3,2,3,2,5,4,3]return = 3numbers[0] and numbers[1] are 4 and 3. There are three elements in numbers that are not equal to 4 or 3:
numbers[2] = 2numbers[4] = 2numbers[5] = 5
So, the answer is 3.
Example 2
numbers = [3,3,1,1,3]return = 2numbers[0] and numbers[1] are both 3. There are two elements in numbers that are not equal to 3:
numbers[2] = 1numbers[3] = 1
So, the answer is 2.
Example 3
numbers = [-2]return = 0numbers[0] is -2, and numbers[1] does not exist, so the only rule is to count numbers different from -2. There are no elements in numbers that are not equal to -2, so the answer is 0.
Constraints
1 <= numbers.length <= 1000-1000 <= numbers[i] <= 1000
More Airbnb Online Assessment questions
- Bouncing DiagonalsOA · Seen Dec 2026
- Garden Sprinkler PlacementOA · Seen Dec 2026
- Theme Park Shuttle Wait TimeOA · Seen Dec 2026
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
Similar questions at other companies
- Closest NumbersHeadlands Technologies · OAHeadlands Technologies interview questions
- REST API: Country CodesHackerRank · OAHackerRank interview questions
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Build the Task HierarchyPendo · OA
- Lowest Number in an Open RangeCapital One · OACapital One interview questions
- Missing IntervalsIBM · OAIBM interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)