Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
arr[] = {1,2,3,2,4,1,5}
how to solve using hashmap in the given array in which the number is divisible by 20

What I have tried:

i have tried using 20/ int a, int b in hashmap.get and put by using for loop
Posted
Updated 2-Jul-22 3:10am
Comments
Patrice T 2-Jul-22 6:14am    
Tery to show your work do far.

A simple O(N2) algorithm can be implemented using two nested loops: in the other one you check if the current item divides 20 and, if the divisibility test passed, you execute the inner one trying to find its companion.

The condition for checking the divisibility is
Java
((20 % arr[i]) == 0)
 
Share this answer
 
Comments
Maciej Los 2-Jul-22 15:11pm    
5ed!
"Divisible by 20" means the other way round: 40 is divisible by 20, 80 is also divisible by 20 - because in both cases when you divide X by Y you get a remainder of 0.
41 is not, 87 is not, 70 is not, and no number between 1 and 19 inclusive is divisible by 20.

Java has a remainder operator: Modulus in Java | Remainder or Modulus Operator in Java | Edureka[^] so try using that on the numbers in your array.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
v2
Comments
CPallini 2-Jul-22 8:59am    
JavaScript?!
:-D
OriginalGriff 2-Jul-22 9:19am    
Auto-f'ing-complete ...
Fixed. :thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900