MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / Split_the_String

Function Split_the_String

Split_the_String.js:1–51  ·  view source on GitHub ↗
(S,k)

Source from the content-addressed store, hash-verified

1function Split_the_String(S,k){
2 let n = S.length;
3 var arr = new Array(k);
4 var i=n/k;
5 var j=0;
6 var res="";
7 var m=0,m1=0,m2=0;
8 while(m<k){
9 if(j<=i)
10 res+=S[m1++];
11 else{
12 arr[m]=parseInt(res,2);
13 res="";
14
15 j=0;
16 m++;
17 }
18 j++;
19 }
20 var l = arr[0];
21 for(let i=1;i<arr.length;i++){
22 if(arr[i]!=l)m2=1;
23 }
24 i=n/k;
25 m=0;
26 m1=0;
27 j=0;
28 if(m2==1){
29 while(m<k){
30 if(j<i-1)
31 res+=S[m1++];
32 else{
33 if(m==k-1)res+=S[m1++]+S[m1];
34 arr[m]=parseInt(res,2);
35 res="";
36 j=0;
37 m++;
38 }
39 j++;
40 }
41
42 l = arr[0];
43 m2=0;
44 for(let i=1;i<arr.length;i++){
45 if(arr[i]!=l)m2=1;
46 }
47
48 if(m2==1)return 'NO';
49 }
50 return 'YES';
51}
52console.log(Split_the_String("010100101",2));
53
54

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected