FastPrepCount Soldiers with a Next-Rank Superior
Problems/Count Soldiers with a Next-Rank Superior

Count Soldiers with a Next-Rank Superior

Marshall Wace logoMarshall Wace● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The photographed report supplies the next-rank rule, unlimited reports, three examples and array-size bound, but cuts off the rank-value range. This practice version uses nonnegative bounded ranks and matches at about 95%.

Each entry of ranks is the rank of one soldier. A soldier of rank x can report to any soldier of rank exactly x + 1.

A superior may receive reports from any number of soldiers. Count the soldiers who have at least one eligible superior in the array. Count soldiers individually, including repeated ranks.

Function

solution(ranks: int[]) → int

Examples

Example 1

ranks = [3,4,3,0,2,2,3,0,0]return = 5

The three rank-three soldiers can report to rank four; the two rank-two soldiers can report to rank three. Rank zero has no rank-one superior.

Example 2

ranks = [4,2,0]return = 0

No rank is exactly one less than another rank in the array.

Example 3

ranks = [4,4,3,3,1,0]return = 3

Two rank-three soldiers have rank-four superiors, and rank zero has a rank-one superior.

Constraints

  • 2 <= ranks.length <= 100000.
  • For this exercise, assume 0 <= ranks[i] <= 10^9.

More Marshall Wace Online Assessment questions

  • Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
  • Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
  • Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
  • Maximum Events in a 60-Second WindowOA · Seen Aug 2025
  • Successful Logins from Multiple CountriesOA · Seen Aug 2025
  • Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
  • Shortest String After Erasing Equal PairsOA · Seen Nov 2024
  • Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
  • Generate Unique Company Email AddressesOA · Seen Apr 2024
  • Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • Items SortAkuna Capital · OAAkuna Capital interview questions
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Array Rank TransformTata Consultancy Services · OATata Consultancy Services interview questions
  • Find Max Health SumAmazon · OA
  • Influencers SquadTikTok · OATikTok interview questions
  • Count Teams Outscoring a Target TeamBloomberg LP · OABloomberg LP interview questions
  • Sort by Frequency, Then ValueC3.ai · OAC3.ai interview questions

Interview reports that mention this question

  • Marshall Wace Coding Tests: 11 Experiences (Part 2 of 3)
  • Marshall Wace Quant and Coding OA: 19 Experiences (Part 1 of 3)

Marshall Wace interview experiences

  • Marshall Wace Older Quant Tests: 5 Experiences (Part 3 of 3)
All Marshall Wace interview questionsSee Marshall Wace hiring insights
Saved
class Solution {
    public int solution(int[] ranks) {
        // Write your solution here.
    }
}
Checking account…