Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

It is a **universal** iterator as we can apply it to any Collection object. By using Iterator, we can perform both read and remove operations.Try this problem using **Iterator**.

Given an array **arr[]** of **n** integrs which are to be put in an ArrayList and an integer **k**. Iterate the Array List using iterator and remove all the numbers of the ArrayList which are less than **k**. And then return the sorted ArrayList.

**Example 1:**

Input:n =5,k =8arr[] ={1, 6, 9, 2, 11}Output:[9, 11]Explanation:The numbers 1, 6 and 2 are less than 8, and so they are removed.

**Example 2:**

Input:n =4,k =13arr[] ={1, 4, 6, 9}Output:[]Explanation:All the numbers are less than 13, and so they are removed.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **javaIterator()** which takes 2 Integers n, k, and an array arr[] of n integers as input and returns a sorted ArrayList after removing all elements less than k.

**Expected Time Complexity:** O(n)

**Expected Auxiliary Space:** O(n)

**Constraints:**

1 <= n,k <= 10^{5}

1 <= arr[i] <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Java Iterator

...