Menu

Intelligent Substrings Two Types Characters Particular Language Special Normal Character S Q43857366

Intelligent Substrings:

There are two types of characters in a particular language:special and normal. A character is special if its value is 1 andnormal if its value is 0. Given string s, return the longestsubstring of s that contains at most k normal characters. Whether acharacter is normal is determined by a 26-digit bit string namedcharValue. Each digit in charValue corresponds to a lowercaseletter in the English alphabet.

Example:

s = ‘abcde’

alphabet = abcdefghijklmnopqrstuvwxyz

charValue = 10101111111111111111111111

For clarity, the alphabet is aligned with charValue below:

alphabet = abcdefghijklmnopqrstuvwxyz

charValue = 10101111111111111111111111

The only normal characters in the language (according tocharValue) are b and d. The string s contains both of thesecharacters. For k = 2, the longest substring of s that contains atmost k = 2 normal characters is 5 characters long, abcde, so thereturn value is 5. If k = 1 instead, then the possible substringsare [‘b’, ‘d’, ‘ab’, ‘bc’, ‘cd’, ‘de’, ‘abc’, ‘cde’]. The longestsubstrings are 3 characters long, which would mean a return valueof 3.

16. Intelligent Substring There are two types of characters in a particular language: special and normal. A character is spec

Function Description Complete the function getSpecialSubstring in the editor below. getSpecialSubstring has the following par

Sample Case 0 Sample Input 0 STDIN Function giraffe S = giraffe! k = 2 charValue = 01111001111111111011111111 011110011111

telligent Substring X + V.hackerrank.com/test/7ci6fsmifiq/questions/dn3kgc4 1110 5S algos Dgit Dgsoc SUMMER MOOC List Massiv.

errank.com/test/7ciófsmlfiq/questions/dn3kgc41110 algos git D gsoc SUMMER MOOC List | Massiv... python-data science C o ld mu

solve using C++/Java.

16. Intelligent Substring There are two types of characters in a particular language: special and normal. A character is special if its value is 1 and normal if its value is 0. Given string s, return the longest substring of s that contains at most k normal characters. Whether a character is normal is determined by a 26-digit bit string named charValue. Each digit in charValue corresponds to a lowercase letter in the English alphabet. Example: s = ‘abcde alphabet = abcdefghijklmnopqrstuvwxyz charValue = 10101111111111111111111111 For clarity, the alphabet is aligned with charValue below: alphabet = abcdefghijklmnopqrstuvwxyz charvalue = 10101111111111111111111111 The only normal characters in the language (according to charValue) are b and d. The string s contains both of these characters. For k = 2, the longest substring of s that contains at most k = 2 normal characters is 5 characters long, abcde, so the return value is 5. If k = 1 instead, then the possible substrings are [‘b’, ‘d, ‘ab’, ‘bc), ‘cd’, ‘de’, ‘abc, ‘cde’). The longest substrings are 3 characters long, which would mean a return value of 3. Function Description Complete the function getSpecialSubstring in the editor below. Function Description Complete the function getSpecialSubstring in the editor below. getSpecialSubstring has the following parameter(s): string s: the input string int k the maximum number of normal characters allowed in a substring string charValue: a string representing special or normal for each letter of the alphabet, ascii[a-z] Return: int: an integer that denotes the length of the longest substring of s with at most k normal characters Constraints • 1 s length of s < 105 • 1 s length of k < the length of s The length of charValue = 26 • All values in charValue will be either 0 or 1 Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains a string s, the input string. The second line contains an integer k, the number of normal characters allowed in a substring. The third line contains a string charValue, where each character denotes the value of a character in [a…z], aligned by index. Sample Case 0 Sample Input 0 STDIN Function giraffe S = ‘giraffe! k = 2 charValue = ‘01111001111111111011111111’ 01111001111111111011111111 → Sample Output 0 3 Explanation 0 Align the alphabet with charValue: abcdefghijklmnopqrstuvwxyz 01111001111111111011111111 Normal characters are in the set {a, f, g, r). All others are special. For the string giraffe the longest possible substrings with 2 normal characters include gir, ira and ffe. gir: The normal characters are g and r. ira: The normal characters are r and a ffe: The normal characters are f and f. The maximum length substring has a length of 3. telligent Substring X + V.hackerrank.com/test/7ci6fsmifiq/questions/dn3kgc4 1110 5S algos Dgit Dgsoc SUMMER MOOC List Massiv… python-data science o ld music 7 FARIDA – HINTS A… O In 101111111 C++ • Autocomplete Ready O 1 > #include <bits/stdc++.h> … in the set e special Complete the ‘getSpecialSubstring function below. the longest ith 2 lude gir, ira The function is expected to return an INTEGER. | * The function accepts following parameters: * 1. STRINGS * 2. INTEGER K. * 3. STRING charValue cters 17 icters cters 18 int getSpecialSubstring(string s, int k, string charValue) { 20 21 } 22 > int main() … substring errank.com/test/7ciófsmlfiq/questions/dn3kgc41110 algos git D gsoc SUMMER MOOC List | Massiv… python-data science C o ld music <E FARIDA – HINTS A… O Inside Story 11111 Java 8 Autocomplete Ready O e set cial. 1 > import java.io.*; 14 15 class Result { ngest • Complete the ‘getSpecialSubstring’ function below. gir, ira * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. STRINGS * 2. INTEGER K * 3. STRING charValue public static int getSpecialSubstring(String s, int k, String charValue) { // Write your code here ring 33 34 > public class Solution {… 00000 Test Results Custom Input Show transcribed image text 16. Intelligent Substring There are two types of characters in a particular language: special and normal. A character is special if its value is 1 and normal if its value is 0. Given string s, return the longest substring of s that contains at most k normal characters. Whether a character is normal is determined by a 26-digit bit string named charValue. Each digit in charValue corresponds to a lowercase letter in the English alphabet. Example: s = ‘abcde alphabet = abcdefghijklmnopqrstuvwxyz charValue = 10101111111111111111111111 For clarity, the alphabet is aligned with charValue below: alphabet = abcdefghijklmnopqrstuvwxyz charvalue = 10101111111111111111111111 The only normal characters in the language (according to charValue) are b and d. The string s contains both of these characters. For k = 2, the longest substring of s that contains at most k = 2 normal characters is 5 characters long, abcde, so the return value is 5. If k = 1 instead, then the possible substrings are [‘b’, ‘d, ‘ab’, ‘bc), ‘cd’, ‘de’, ‘abc, ‘cde’). The longest substrings are 3 characters long, which would mean a return value of 3. Function Description Complete the function getSpecialSubstring in the editor below.
Function Description Complete the function getSpecialSubstring in the editor below. getSpecialSubstring has the following parameter(s): string s: the input string int k the maximum number of normal characters allowed in a substring string charValue: a string representing special or normal for each letter of the alphabet, ascii[a-z] Return: int: an integer that denotes the length of the longest substring of s with at most k normal characters Constraints • 1 s length of s int main() … substring
errank.com/test/7ciófsmlfiq/questions/dn3kgc41110 algos git D gsoc SUMMER MOOC List | Massiv… python-data science C o ld music import java.io.*; 14 15 class Result { ngest • Complete the ‘getSpecialSubstring’ function below. gir, ira * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. STRINGS * 2. INTEGER K * 3. STRING charValue public static int getSpecialSubstring(String s, int k, String charValue) { // Write your code here ring 33 34 > public class Solution {… 00000 Test Results Custom Input

Expert Answer


 

Short Summary:

  • Implemented using C++
  • Follow the inline comments for program flow
  • Wrote a test driver (main method) to test the use cases.

Source code:

#include <bits/stdc++.h>
using namespace std; . . . . .

OR