+ 2

somebody help me to find minimum pair of array. i cannot figure out it. please help

this code made by me to find minimum pair of array. but i can't figure it out.

23rd Nov 2020, 3:36 PM
Rahul Diwan
Rahul Diwan - avatar
3 Respostas
+ 2
What is the criteria of a minimum pair here? You have an array with 10 elements but only fill first few of it (6 elements), why?
23rd Nov 2020, 4:30 PM
Ipang
+ 2
If you want the number with minimum pairs. Which is in your case 7. You could use a map. Maps/ Hash map in java are great way to map key value pairs. You can count the number of occurrence of value in linear time. Then loops through the map to find the key with least pair.
23rd Nov 2020, 4:48 PM
Akib
Akib - avatar
+ 1
public class Program { public static void main(String[] args) { int[] array = new int[10]; array[0]=6; array[1]=6; array[2]=6; array[3]=6; array[4]=7; array[5]=7; int i,j,min=0; int size=array.length; for(i=0;i==size-1;i=j) { int flag=0; for(j=i;array[i]==array[j] ;j++) { flag++; min=flag; } if(min<=flag) { min=flag; } } System.out.println(min); } }
23rd Nov 2020, 3:36 PM
Rahul Diwan
Rahul Diwan - avatar