(15)
imes
LC. lens
x
Inbo
bo x
M Ac
LC Len:
lear
Fina
Inbc
You
hackerrank.com/test/aeh43ecqg31/questions/at91gh7n34s
3m left
Language
Java 8
(1) Environment
Q Autocomplete R
2. Unequal Elements
A test needs to be prepared on the HackerRank platform with questions from different sets of skills to assess candidates. Given an array, skills, of size n, where skills[i] denotes the skill type of the i^(th) question, select skills for the questions on the test. The skills should be grouped together as much as possible. The goal is to find the maximum length of a subsequence of skills such that there are no more than k unequal adjacent elements in the subsequence. Formally, find a subsequence of skills, call it x, of length m such that there are at most k indices where x[i]!=x[i+1] for all 1,3,4
31,2,3,41,5
4,3=[1,1,2,3,2,1],k=2x=[1,1,2,2,1]x[1]!=x[2]x[3]!=x[4]0<=i
Note: A subsequence of an array is obtained by deleting several elements of the array (possibly zero or all) without changing the order of the remaining elements. For example, 1,3,4
3 are subsequences of 1,2,3,4 whereas 1,5
4,3 are not.
Example
skills =[1,1,2,3,2,1],k=2.
The longest possible subsequence is x=[1,1,2,2,1]. There are only two indices where x[1]!=x[2] and x[3] !=x[4].
Return its length, 5.
Function Description
Complete the function findMaxLength in the editor below.
findMaxLength has the following parameter(s):
findMaxLength has the following parameter(s):
Test Results
Custom Input
Custom Input
Give code in java8
Language Java 8
vEnvironment
Autocomplete R
2. Unequal Elements
1>import java.io.*; 14 15 class Result 16
A test needs to be prepared on the HackerRank platform with questions from different sets of skills to assess candidates. Given an array, skills, of size n where skills[i] denotes the skill type of the i^(th) question, select skills for the questions on the test. The skills should be grouped together as much as possible. The goal is to find the maximum length of a subsequence of skills such that there are no more than k unequal adjacent elements in the subsequence. Formally, find a subsequence of skills, call it x, of length m such that there are at most k indices where x[i]!=x[i+1] for all 0<m
ALL
18 19 20 21 22 23 24 25 26 27 28 29
Complete the findMaxLength function below
.
* The function is expected to return an INTEGER. The function accepts following parameters: 1. INTEGER_ARRAY skills 2. INTEGER k */
public static int findMaxLength(List<Integer> skills, int k) { // Write your code here
Note: A subsequence of an array is obtained by deleting several elements of the array (possibly zero or all) without changing the order of the remaining elements. For example [1,3,4] [3] are subsequences of [1, 2, 3, 4] whereas [1, 5], [4, 3] are not
31 32 33 public class Solution {
Example skills =[1,1,2,3,2,1],k=2.
The longest possible subsequence is x=[1,1,2,2,1]. There are only two indices where x[1]!=x[2] and x[3]!=x[4]. Return its length, 5.
Function Description Complete the function findMaxLength in the editor below
findMaxLength has the following parameter(s):
Test Results
Custom Input
80 F3
Q
F2
@ 2
# 3
% 5
& 7
4
6
8
9
0
Q
W
E
R
T
Y
U
0
A
S
D
F
G
H
Z
X
c
B
N