an ultra easy question to cehck for alternating values of groups value (0->1->0 or 1->0 and so on). I thought of checking for index of 0 and 1 to calc seaprately and take the bigger longer value but actually the first value that is in the list is guaranteed to be the longest.
notice if we have 0,1,0,1,0 the first value (0) is our starting point, not the 1 at index =1.
class Solution {
public List<String> getLongestSubsequence(String[] words, int[] groups) {
int check=-1;
List<String> ans =new ArrayList<>();
for (int i =0; i<words.length;i++){
if(groups[i]!=check){
check=groups[i];
ans.add(words[i]);
}
}
// String[] realAns= new String[ans.size()];
// for(int i =0; i<ans.size();i++){
// realAns[i]=ans.get(i);
// }
return ans;
}
}
n time
n space