Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Wipro-Practice | 21 Aug | NON-PRP

 Wipro-Practice | 21 Aug

1.

PROBLEM STATEMENT :

A String is Pretty if it can be represented as k concatenated copies of some string. For example, the

string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a

5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to

reorder the letters in the string s in such a way that the resulting string is a k-string.

Input Format

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are

lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length

of string s.

Output Format

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single

output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "-1" (without quotes).

Examples

Sample input

2

aazz

Sample Output

azaz


Python Solution:

n=int(input())

s=sorted(input())

t=s[::n]*n

print("".join(t) if sorted(t)==s else -1)


2.PROBLEM STATEMENT:

Kaaliya has a gadget which is used in finding number of Amazing Two character string , but as now

Doremon is not in town and chhutaki wants to find number of Amazing Two character string to impress

Suzuka. Help chhutaki in finding the answer.

Two character strings are the strings consisting of only two characters "X" and "Y". A string is “Amazing

two character string" if

a) It does not have leading "X" character.

b) It does not contain P consecutive "X" characters.

Your task is to find total number of “Amazing two character strings of length N.

Input Format

The first line contains the number of test cases T . Each test case consists of two space separated

integers - N and P .

Output Format

For each test case output total number of “Amazing two character strings of length N modulo

1000000007(10^9+7).

Constraints

1 <= T <= 100

1 <= N <= 10^4

1 <= P <= 10

SAMPLE INPUT

2

2 1

4 2

SAMPLE OUTPUT

1

5


C SOLUTION:

#include<stdio.h>

#include<string.h>

#define mod 1000000007 

 

int main()

{

long long int dp[10005]; 

int n,t,k,i,j;

scanf("%d",&t);

while(t--)

{

memset(dp,0,sizeof(dp));

scanf("%d%d",&n,&k);

 

dp[0]=1;

for(i=1;i<=n;i++)

{

for(j=i-1;(j>=0)&&(i-j<=k);j--)

{

dp[i]+=dp[j];

dp[i]=(dp[i])%mod;

}

}

printf("%lld\n",dp[n]);

}

return 0;

}

Post a Comment

Previous Post Next Post