FastPrepTop N Longest Sentences
Problems/Top N Longest Sentences

Top N Longest Sentences

Deloitte logoDeloitte● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the first N longest sentences. It does not say the exact output order, how ties work, which characters are allowed, or the input limits. Here sentences are ranked by length and equal lengths keep their original order. Sentences are printable ASCII strings. Our version is about 92% the same as the reported question.

You are given an array of ASCII strings sentences and an integer n. Rank the strings by decreasing character count. If two strings have the same length, the one that appeared earlier in the input ranks first.

Return the first n strings in that ranking.

Function

topLongestSentences(sentences: String[], n: int) → String[]

Examples

Example 1

sentences = ["short","the longest one","medium text","tiny"]n = 2return = ["the longest one","medium text"]

These are the two strings with the greatest character counts.

Example 2

sentences = ["bbb","aa","ccc","d"]n = 2return = ["bbb","ccc"]

bbb and ccc tie at length 3, so their original order is preserved.

Constraints

  • 1 <= sentences.length <= 100000
  • 1 <= n <= sentences.length
  • 0 <= sentences[i].length <= 1000
  • Every string contains only printable ASCII characters.
  • The sum of all string lengths is at most 100000.

More Deloitte Online Assessment questions

  • Seventh Nearest PalindromeOA · Seen May 2026
  • Minimum Deletions for a Non-PalindromeOA · Seen Jul 2025
  • Minimum-Cost Solar Rooftop AllocationOA · Seen Jul 2025
  • Pair Elements with Even SumsOA · Seen Jul 2025
  • Count Divisible PermutationsOA · Seen Jan 2025
  • Largest Element in an ArrayOA · Seen Nov 2024
  • Install Carbon FiltersOA · Seen Oct 2023
  • Longest Substring with Even OccurrencesOA · Seen Oct 2023
  • Maximum Sum RectangleOA · Seen Apr 2022
  • Annual Bank Balance with Monthly Card FeesOA · Seen Jan 2022

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Frequently Bought TogetherAmazon · OA
  • Aggregate Paginated Project Run RecordsReplit · OA
  • Product Record SearchWells Fargo · OAWells Fargo interview questions
  • Sort Ancestral NamesRoblox · OARoblox interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Parse and Sort Integer DataLegora · PHONE SCREEN

Interview reports that mention this question

  • Deloitte New Grad Tech OA and Interview Questions: 14 Experiences
All Deloitte interview questionsSee Deloitte hiring insights
Saved
class Solution {
    public String[] topLongestSentences(String[] sentences, int n) {
        // Write your solution here.
    }
}
Checking account…