Practice: Write-the-Stream Coding Questions
50 min · Advanced
Stream coding questions follow a small number of patterns: sort and skip, group and count, filter a frequency map, and group then aggregate. Learn each pattern once, say it aloud while you write it, and most "write this with streams" questions become routine.
Topics in this lesson
- Round 1: second highest, duplicates, frequency, first non-repeated
- Round 2: group employees by department and average salary
- Round 3: convert a loop to a stream and back
- Round 4: predict the output on laziness and Optional
Interview questions this lesson answers
- How do you find the second highest number in a list using streams?
- How would you find the Nth highest salary with streams?
- How do you find duplicate elements with streams?
- How do you remove duplicates but keep the original order?
- How do you count the frequency of each character in a string?
- How do you find the first non-repeated character with a stream pipeline?
- How do you count words in a sentence?
- How do you get the top three most frequent words?
- How do you group employees by department and find the average salary?
- How do you find the highest-paid employee in each department?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.