## Bonsavic Petro

- 0of 0 votes

AnswersJavascript solution for this question???

- Bonsavic Petro in United States

Given a list of characters, write a function to output a list of length of minimum non overlapping subsequences that can partition the input list.

For example:

Input : [a,b,c]

Output: [1,1,1]

Explanation: There are no repeated characters.

Input : [a,b,c,a]

Output: [4]

Explanation: The 'a' is repeated so one subsequence is between a to last a.

Input : [a,b,c,b,a,e,b,a,d,f,g,d,f,i,f,k,l,m,n,m,l]

Output: [8,7,6]

Explanation: max length from 1st 'a' to last 'a' is 8.

1st 'f' to last is 6 adding d to it = 7

so on| Report Duplicate | Flag

Jabong JavaScript - 0of 0 votes

Answerswhat is JAVASCRIPT Solution for this questions:

- Bonsavic Petro in United States

Michelle has created a word game for her students. The word game begins with Michelle writing a string and a number, K, on the board.

The students must find a substring of size K such that there is exactly one character that is repeated one;

in other words, there should be k - 1 distinct characters in the substring.

Write an algorithm to help the students find the correct answer. If no such substring can be found, return an empty list;

if multiple such substrings exist, return all them, without repetitions. The order in which the substrings are does not matter.

Input:

The input to the function/method consists of two arguments - inputString, representing the string written by the teacher;

num an integer representing the number, K, written by the teacher on the board.

Output:

Return a list of all substrings of inputString with K characters, that have k-1 distinct character i.e.

exactly one character is repeated, or an empty list if no such substring exist in inputString.

The order in which the substrings are returned does not matter.

Constraints:

The input integer can only be greater than or equal to 0 and less than or equal to 26 (0 <= num <= 26)

The input string consists of only lowercase alphabetic characters.

Example

Input:

inputString = awaglk

num = 4

Output:

[awag]

Explanation:

The substrings are {awag, wagl, aglk}

The answer is 'awag' as it has 3 distinct characters in a string of size 4, and only one character is repeated twice.| Report Duplicate | Flag

What is JAVASCRIPT solution for this???

- Bonsavic Petro February 12, 2018Maddy,

Your solution is passing the the test based on what they expected below..

Explanation:

The substrings are {awag, wagl, aglk}

The answer is 'awag' as it has 3 distinct characters in a string of size 4, and only one character is repeated twice.

@ vCillusion,,, can you add your solution here.

- Bonsavic Petro February 12, 2018**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

@koolkhuch Thanks a lot

- Bonsavic Petro February 13, 2018