fork download
  1. // "A news aggregator app pulls headlines from k different sources. Each source provides its headlines already sorted by timestamp (earliest first). The app needs to combine all headlines into a single timeline, sorted by timestamp globally.
  2.  
  3. // Given k sorted arrays, merge them into one sorted array.
  4. // (1 <= k <= 500; total number of elements across all arrays n <= 10^5; 0 <= element <= 10^9)
  5.  
  6. // Example 1:
  7. // Input: lists = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
  8. // Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
  9. // Explanation: Three sources, each sorted. Merged in global order.
  10.  
  11. // Example 2:
  12. // Input: lists = [[1, 3, 5], [2, 4, 6], []]
  13. // Output: [1, 2, 3, 4, 5, 6]
  14. // Explanation: Third source is empty — just merge the first two. Empty arrays should be handled gracefully.
  15.  
  16. // Example 3:
  17. // Input: lists = [[10]]
  18. // Output: [10]
  19. // Explanation: Single source with one element.
  20.  
  21. // Example 4:
  22. // Input: lists = [[], [], []]
  23. // Output: []
  24. // Explanation: All sources are empty.
  25.  
  26. // Example 5:
  27. // Input: lists = [[1, 1, 1], [1, 1], [1]]
  28. // Output: [1, 1, 1, 1, 1, 1]
  29. // Explanation: Duplicates across sources — all kept, stable relative order."
  30.  
  31. import java.util.*;
  32. import java.lang.*;
  33. import java.io.*;
  34.  
  35. /* Name of the class has to be "Main" only if the class is public. */
  36. class Ideone
  37. {
  38. public static void main (String[] args) throws java.lang.Exception
  39. {
  40. // your code goes here
  41. }
  42. }
Success #stdin #stdout 0.07s 35012KB
stdin
Standard input is empty
stdout
Standard output is empty