We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
List<Integer> list1 = new ArrayList<>(Arrays.asList(6, 5));
List list2 = new ArrayList<>(Arrays.asList(5, 3, 5, 2, 3, 2));
List> list3 = new ArrayList<>();
list3.add(list1);
list3.add(list2);
maxUniqeNumbers(list3);
System.out.println (maxUniqeNumbers(list3));
}
public static int maxUniqeNumbers (List> list3) {
int max = 3;
int x = 3;
for (List innerList : list3) {
if (innerList.size () < 3) {
continue ;
}
else {
int i = 0 ;
// int n = 0 ;
for (i = 0 ; i < innerList.size() - 2 ; i++) {
int m = 0;
if (innerList.get (i) == innerList.get (i+1)) {
m++;
}
if (innerList.get (i) == innerList.get (i+2)) {
m++;
}
if (innerList.get (i+2) == innerList.get (i+1)) {
m++;
}
if (m < x) {
x = m ;
}
}
}
}
return max - x ;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Dequeue
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
List list2 = new ArrayList<>(Arrays.asList(5, 3, 5, 2, 3, 2)); List> list3 = new ArrayList<>(); list3.add(list1); list3.add(list2); maxUniqeNumbers(list3); System.out.println (maxUniqeNumbers(list3)); } public static int maxUniqeNumbers (List> list3) { int max = 3; int x = 3; for (List innerList : list3) { if (innerList.size () < 3) { continue ; } else { int i = 0 ; // int n = 0 ;
if (m < x) { x = m ;
} }
} }