## Abhishek.Mathur.CA

BAN USER- 0of 0 votes

AnswersConsider a string A containing exactly X characters. A variant of A, A(k), can be obtained by doing a cyclic shift of A starting from position k (0 <= k < X). The number of characters after the shift in A(k) will remain the same as they were in A. Every j-th character (0 <= j <= X-1) of A(k) is equal to (k+j)%X character of A. We will call A a classic word if there are exactly M positions k such that A(k) = A

- Abhishek.Mathur.CA in United States

You are given array Q containing exactly R strings. For each permutation s = (s[0], s[1], ..., s[R-1]) of integers between 0 and R-1, inclusive, we can define a string generated by this permutation as a concatenation Q[s[0]] + Q[s[1]] + ... + Q[s[R-1]]. Find the number of permutations that generate classic words. All indices in this problem are 0-based

Constraints

Set Q will contain between 1 and 8 elements, inclusive. Each element will have 1 to 20 characters, inclusive

M will be between 1 and 200, inclusive

Input Format

Line 1: comma separated strings representing set Q

Line 2: Integer M

Output Format

Number of permutations that generate classic words

Sample Input

CD,QCCD,QC

2

Sample Output

3

Explanation

The classic words are "CDQCCDQC" and "QCCDQCCD". Permutation 0, 1, 2 generates the first, and 1, 2, 0 and 2, 0, 1 generate the second| Report Duplicate | Flag | PURGE

unknown Software Developer - 0of 0 votes

AnswersYour friend has invented a new compound consisting of N elements. However, he has forgotten the amount of each element that goes into the recipe.

- Abhishek.Mathur.CA in United States

For N-1 pairs of elements, he remembers the proportion in which the elements within each pair should be added to the compound. Fortunately, these N-1 proportions are sufficient to restore the recipe of the entire compound.

You are given N-1 proportions as String. Each String is formatted "#<a> and #<b> as <p>:<q>" (quotes for clarity), which means that the mass of element <a> divided by the mass of element <b> in the cocktail must be equal to <p>/<q> (all elements are 0-indexed). Print exactly N elements, where the first line is the mass of element 0 and second line is the mass of element 1 and so on... such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Input

Line 1: N

Line 2 .. N: proportion_i

Output

N lines of masses, as stated in the problem statement

Input Explanation

Line 1: N, the number of elements

Line 2 to line N: N-1 proportions, format described in the problem statement

Output Explanation

Output will contain exactly N lines, each line is the mass of the element such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Sample Input

3

#0 and #1 as 9:8

#1 and #2 as 9:8

Sample Output

81

72

64| Report Duplicate | Flag | PURGE

unknown Software Developer - 0of 0 votes

AnswersConsider a social website SocialX, where friends connect to each other, just as they do on Facebook

- Abhishek.Mathur.CA in United States

Friendship on SocialX is symmetric (if X is a friend of Z, then Z is also a friend of X) however not transient (if X and Z are friends and Z and Y are friends, then X and Y are not necessarily friends)

The term "k-joined" is defined as follows. If two people are friends, they are called 1-joined. For k >= 1, two people X and Z are called (k+1)-joined if X and Z are k-joined, or if there exists a person Y such that X and Y are k-joined and Y and Z are friends.

"Approachable Score" is defined as follows. If two people X and Z are not friends, then their Approachable Score is the fewest number of people (other than themselves) who must be removed from the network in order for X and Z to not be 3-joined. The higher the Approachable Score, the more likely it is that X and Z know each other.

Given a set of friends containing exactly K elements, where K is the number of people in the network. People are numbered from 0 to K-1. The j-th character of the i-th element of friends is '1' if i and j are friends, and '0' otherwise. Return the Approachable Score for personX and personZ

Constraints

Set of friends will contain exactly K (1 < K < 41) elements, where each element will contain exactly K characters. Each character will either be '0' or '1'

friends[i][j] will always be equal to friends[j][i] and friends[i][i] will always be equal to 0

friend[personX][personZ] will be equal to 0 and personX will never be equal to personZ

Input Format

Line 1: comma separated K elements representing friends

Line 2: Integer representing personX

Line 3: Integer representing personZ

Output Format

Integer representing Approachable Score

Sample Input

0100,1010,0101,0010

0

3

Sample Output

1

Explanation

Either remove person 1 or person 2 to get an Approachable Score of 1 for person 0 and 3| Report Duplicate | Flag | PURGE

unknown Software Developer - 1of 1 vote

AnswerYou are given a list of tasks as an integer array, task_costs. Every i-th element of task_costs represents a task and requires task_costs[i] seconds to complete. All tasks listed in the array are independent of other tasks.

- Abhishek.Mathur.CA in United States

It is required to finish all the tasks independently and as soon as possible. You are given a single worker robot to start taking the tasks and finish them one at a time. However if you like, you can divide the worker robot in two. Each resulting robot can then be further divided into two and so on. There is a cost, in seconds, of dividing a robot in two, represented by robot_divide_cost.

You can assign an independent task to any available robot, however you can't interrupt or divide a robot while it is working on the assigned task. At the same time you can't assign a task to any robot while its in the process of getting divided.

To keep things simple you can't allow multiple robots to work on the same task. At any given time only one robot can work on a task and finish it. Once any particular robot finishes a task it can't be assigned any further tasks.

Given a list of tasks and cost of dividing a robot, find the least amount of time to finish all tasks.

Input:

3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,360,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600

3600

Expected Output: 25200

Input:

1113,773,824,822,1458,1257,908,1320,780,1016,1066,861,1150,718,1405,738,718,980,1037,946,1121,1349,805,1378,1308,1272,1532,779,875,1392,982,1282,744,723,1033,1067,1158,1071,742,683,678,762,686,1143,862,1231,765,1472,1560,1085

3147

Expected Output: 20040| Report Duplicate | Flag | PURGE

unknown Software Developer - 0of 0 votes

AnswersYou are given a string X and integer k (0 <= k < length of X). For each value of k you can look at a sub-string of X starting from index 0 to index k and choose to reverse it. As an example, let X = LMNAP and k = 2. If you reverse the sub-string of X between 0 and 2 you will get NMLAP. Subsequently if choose k = 3 and reverse you will end up with ALMNP.

- Abhishek.Mathur.CA in United States

Given the string X as an input find lexicographically earliest possible string. In the example above, lexicographically ALMNP comes earlier than NMLAP.

Input:

AACAACAABBABACAACBCACCCAAABACABACACCBCCAAABABACBCC

Expected Output: AAAAAAAAAAAAAAAAAAAAAAACCBBBCCBCCCCBCBCCCBCCBBCBCC

Input:

BACBCBCACAACBCBBCCBACCCCAACCBCCAABACAABCAAAABBAABC

Expected Output: AAAAAAAAAAAAAAAAAABCBCBCCCBCBBCCBCCCCCCBCCBCBCBBBC| Report Duplicate | Flag | PURGE

unknown Software Engineer / Developer

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window