FastPrepTail N Lines
Problems/Tail N Lines

Tail N Lines

Confluent logoConfluent● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Implement the Unix tail -n command: given an array of strings representing the lines of a file and an integer n, return the last n lines.

If n is greater than or equal to the total number of lines, return all lines.

Follow-up: Optimize for memory and time complexity. A rolling window (circular buffer / deque of size n) achieves O(n) space and O(L) time where L is the total number of lines — avoiding storing the entire file.

Function

tail(lines: String[], n: int) → String[]

Examples

Example 1

lines = ["a","b","c","d","e"]n = 2return = ["d","e"]

The file has 5 lines. The last 2 lines are "d" and "e".

Example 2

lines = ["a","b","c"]n = 5return = ["a","b","c"]

n=5 exceeds the total number of lines (3), so all lines are returned.

More Confluent interview questions

  • Hard Disk Clustering CostOA · Seen Nov 2026
  • Last Object to Fall Off the TableOA · Seen Nov 2026
  • Sum Symmetric Pairwise RemaindersOA · Seen Nov 2026
  • 0/1 KnapsackOA · Seen Nov 2026
  • Implement tail -nPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Board ValidationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sudoku Puzzle SolverPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Combinations Using Weights One Through KOA · Seen Oct 2026
  • Match a Variadic Function SignaturePHONE SCREEN · Seen Oct 2026
  • Sequential Phrase Search Across DocumentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Card Duel RoundsAirbnb · OAAirbnb interview questions
  • Chess TournamentJP Morgan Chase · OAJP Morgan Chase interview questions
  • Incident MonitorStripe · OAStripe interview questions
  • Realized PnL with Oldest Inventory FirstBelvedere Trading · OA
  • Minimum Jump CostMicrosoft · OAMicrosoft interview questions
  • Buffet Day GainsUpstart · OAUpstart interview questions
  • Minimum of Fixed-Window MaximaJuspay · OA
  • Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
  • Bank Requests with Delayed CashbackRamp · OARamp interview questions
  • Sliding Window Maximum in a MatrixCitadel · OACitadel interview questions

Confluent interview experiences

  • Confluent Older Concurrency Rounds: 12 Experiences (Part 2 of 2)
  • Confluent Concurrency Interviews: 28 Experiences (Part 1 of 2)
  • Confluent SWE OA, Coding and Design Interviews: 19 Experiences
  • Confluent File Manipulation Round (tail -n): 19 Experiences
  • Confluent Coding and System Design Questions: 33 Questions
All Confluent interview questionsSee Confluent hiring insights
Saved
class Solution {
    public String[] tail(String[] lines, int n) {
      // write your code here
    }

}
Checking account…