Greater than 10? You're not a good fit for us

  • 5
  • unavailable
The Oddiozo transshipment center is looking for employees. The only requirement is this: employees must not have more than ten limbs (we don't know where this form of discrimination came from). We'll help them with a program that will create a set of numbers (Set ), add 20 different numbers, and then remove from the set all the numbers greater than 10.
You can't complete this task, because you're not signed in.
Comments(8)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
TurnerLevel 11 , Pittsburgh
30 August, 05:38
Can I assume that a solution for removeAllNumbersGreaterThan10() - first, iterate through the set and set all numbers > 10 to a separate array then iterate through the array removing the set elements WITH NO CONCURRENCY issues fails the requirement is because of Time complexity? Not sure if Iteration<Integer> introduces a savings of Space complexity, but an extra for loop does NOT increase performance much beyond O(n). Can you explain what I am missing in why this solution is not allowed to pass? Please advise.
maniLevel 13 , Harpanahalli
28 June, 12:41
can you please help to find my errors
DinoLevel 13 , Zagreb
10 January, 20:58
Can anyone tell me what doesn't work here? Thanks! package com.codegym.task.task08.task0814; import java.util.HashSet; import java.util.Set; import java.util.Iterator; /* Greater than 10? You're not a good fit for us */ public class Solution { public static HashSet<Integer> createSet() { // write your code here int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; HashSet<Integer> set = new HashSet<Integer>(); for(int aa: a) set.add(aa); return set; } public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) { // write your code here for(Iterator<Integer> iterator = set.iterator(); iterator.hasNext();) { Integer aa = iterator.next(); if (aa > 10) set.remove(aa); } return set; } public static void main(String[] args) { } }
Guadalupe GagnonLevel 35 , Tampa
10 January, 21:13
hit the help button at the top and ask your question. Do not copy/paste your code...... use the slider:
Ed MaphisLevel 20 , Painesville
23 May, 19:26
Hmmm, I didn't know that.
Abhishek RangariLevel 22 , Nagpur
28 October 2018, 18:19
Be sure that the removeAllNumbersGreaterThan10 method works with sets of any size. ? public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) { // write your code here for(Integer num : set){ if(num > 10){ set.remove(num); } } return set; } Does any one is having idea about this ? Can you help me to resolve this issue.
RomanLevel 41
29 October 2018, 06:35
You must use an iterator to remove items.
Deepak JoshiLevel 17 , Nainital
1 May, 15:25
use Irerator to remove items otherwise it will raise ConcurrentModificationException