## Forum Posts

- 2 Answers
**Please help me in solving this (java preferably)**Cool Drink: Kenny loves Coca Cola.

- s April 27, 2020

- There are 'n' different shops in his colony from which he can buy coca cola.

- Each shop has different rate for the same coca cola bottle

- Kenny decided to buy his favorite cool drink for 'm' continuous days.

- Each day Kenny has 'p' money in his hand.

Find out from how many shops, Kenny can buy his favorite cool drink each day.

Prototype: Int[] find TotalShops(int input1, int[] input2 int input3, int] input4)

input1 - Total No. of shops in the colony

input2 - Rate of cool drink in each shop

input3 - No. of days, Kenny is going to buy the cool drink

input4 - Total money, Kenny has with him to buy cool drink, each day

output - No. of shops, in which, Kenny can buy cool drink, each day

Ex - input1 - 5

input2 - {3,10,8,6,11}

input3 - 4

input4 - {1,10,3,11}

output - {0,4,1,5}| Flag | PURGE - 0 Answers
**reverse function with constance element c++**write the functions char * reverse (char * nap, int n) - reverse the string nap except the character at position n (and its "symmetrical" equivalent) and return the inverted string as a result.

Example:`char tab[9]="abcdefgh";`

`cout << reverse(tab,3);`

Output: hgfdecba // d is on same position

- promeq April 24, 2020| Flag | PURGE - 0 Answers
**please help me in solving this!!**Given an integer N, find the Nth number in the fibonacci series. Consider 0 and 1 to be the seed values. In a fibonacci series, each number ( Fibonacci number ) is the sum of the two preceding numbers. The series with 0 and 1 as seed values will go like- 0, 1, 1, 2, 3, 5… .

- abrolrahul9 March 23, 2020

Input

The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N.

Constraints:

1 ≤ T ≤ 50

1 ≤ N ≤ 50

Output

Space separated Nth fibonacci number for each N given in the input| Flag | PURGE - 0 Answers
**Solve this problem**You are asked q queries each of which can be of type 1 or type 2 Type 1 : Report the area of square of side S. Type 2 : Report the area of rectangle of sides L and R.

- abrolrahul9 March 23, 2020

Input

The first line of the input contains single integer Q.

Next Q line contains the queries.

Each query first contains type of query

if query is of type one you are given a single integer S

if query is of type two you are given two integers L and R

Constraints

1 <= Q <= 25

1 <= T <= 2

1 <= S,L,R <= 1000

Output

Output Q line each containing answer to the asked query| Flag | PURGE - 0 Answers
**Confusion in vTable and vptr in C++**Hello Everyone, I want to know the functionality between vTable and vptr in C++. I have faced one interview on skype last week and Recruiter told me this question and i was not given the answer. I have checked on google to find it but still, I am confused. Can anyone know or suggest me some more c++ interview question. which is helpful for my upcoming interviews.

- ankitdixit March 23, 2020| Flag | PURGE - 0 Answers
**Looking for best answer for following question**There is a function checkPassword() which takes a password and return an int which represents the number of correct characters at the correct position in that password.

- jaffar.ramay March 21, 2020

Write a function findPassword() which takes a list of passwords and returns the correct password or null if it doesn't find the correct password. It can make calls to checkPassword() function but it is a very expensive function so the goal is to minimize the calls to checkPassword().

Assume all passwords are of same length.

Example:-

If correct password = abcd

calling checkPassword("axyz") would return 1

Sample Input =

String[] passwords = {"xxyz","axyz", "xbyz","abyz","axyd","xycd"}

System.out.println("password = "+findPassword(passwords));

Sample Output:-

password = abcd| Flag | PURGE - 0 Answers
**How to use List<PairInt>**Given the code below. I need to replace all occurrences of List<List<Integer>> with List<PairInt>. I could not find this PairInt type/class in a library. Do I need to make a new class and what would that be? Thanks!

- randypea February 19, 2020

public static List<List<Integer>> getIdPairsForOptimal(List<List<Integer>> forwardList,

List<List<Integer>> backwardList, int maxDistance) {

List<List<Integer>> result = new LinkedList<List<Integer>>();

forwardList = forwardList.stream().sorted((x1, x2) -> Integer.compare(x2.get(1), x1.get(1)))

.collect(Collectors.toList());

backwardList = backwardList.stream().sorted((x1, x2) -> Integer.compare(x1.get(1), x2.get(1)))

.collect(Collectors.toList());

int maxDist = maxDistance;

while (true) {

for (List<Integer> l : forwardList) {

for (List<Integer> b : backwardList) {

int forward = l.get(1);

int backward = b.get(1);

int tot = (forward + backward);

if (tot > maxDist) {

break;

}

if (tot == maxDist) {

// print the pair of Id and optimum distance

result.add(Arrays.asList(l.get(0), b.get(0), maxDist));

break;

}

}

}

if (result.size() > 0) {

break;

}

maxDist--;

}

return result;

}

}| Flag | PURGE - 0 Answers
**Array Delete Element**Array Deletion

- ranjan.rajiv.2010 November 11, 2019

Mark has an array , A of N elements. He Performs Q queries in it. In each query, he chooses an index I(0-based)

and does the following :

for j=I+1 to N:

if A[j] < A[I]:

A[j] = 0

you need to print what array A looks like after processing all the Q queries.

Note: The queriesare not independentof each other i.e. you need to use the changes array A, for each Query.

Constraints

1 <= T <= 10

1 <= N <= 10^5

1 <= A <= 10^9

1 <= Q <= 10^5

Input

The first line of input has an integer T,denoting the number of test cases. Each test case will consist of 3 lines .

The first line contains 2 space seperated integer, N and Q, denoting the number of element in the arrayand number of queries.

2nd line will have N space seperated integersdenoting the elements in the initial array A.

3rd line will have Q space seperated integers denoting the chosen index in the each query.

Output:

For each test case, output in a seperate line, N space seperated integer denoting the final array A.

Sample Input Output

2

5 2

4 3 4 3 2 4 3 4 0 0

3 2

3 1

3 2 1 3 2 1

2| Flag | PURGE - 6 Answers
**DE SHAW Online Round Question**Given an array of positive integers, each of which represent the number of litres of water in that particular bucket, we have to make the litres of water in every bucket equal.

- pratiks.dce November 09, 2019

We are allowed to do two types of operations any number of times:

1) We can altogether remove a bucket from the sequence

2) We can remove some water from a bucket

We have to tell what is the minimum number of litres removed to make all buckets have the same amount of water.

Eg.

Input:

1 2 3

Output:

2

Explanation:

We remove bucket 1 and remove 1 liter from Bucket 3, so total water removed is 2 liter (the amount of water in the bucket removed gets added to the total water removed).

Any idea on what would be a possible solution to this?| Flag | PURGE - 0 Answers
**C# - Write a program that takes L and R as inputs and display the number of Prime Numbers that lie between L and R (including L and R) and can be represented as a sum of two consecutive prime numbers + 1.**Write a program that takes L and R as inputs and display the number of Prime Numbers that lie between L and R (including L and R) and can be represented as a sum of two consecutive prime numbers + 1.

- nanooshinonome November 07, 2019

The inputs as an example were 1 and 20, and for some odd reason the answer was either 2 or 8.| Flag | PURGE - 0 Answers
**Interview Question**There is a street with n shops and each shop having k items. You need to start from the first and end at the last shop and find the minimum cost to pick items from each shop.

- sdutt.243 June 19, 2019

You can pick one item from each shop.

You cant pick same items from 2 adjacent shops.

Eg :

X 6 1 1

Y 50 50 50

Z 8 20 10

X, Y Z are items to be picked from each shop.

Minimum cost path -> 8,1,1| Flag | PURGE - 0 Answers
**hourglass**Given a 6*6 2D Array, :

- bhawana121998 October 24, 2018

1 1 1 0 0 0

0 1 0 0 0 0

1 1 1 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

We define an hourglass in A to be a subset of values with indices falling in this pattern in arr's graphical representation:

a b c

d

e f g

There are 16 hourglasses in arr, and an hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum.

For example, given the 2D array:

-9 -9 -9 1 1 1

0 -9 0 4 3 2

-9 -9 -9 1 2 3

0 0 8 6 6 0

0 0 0 -2 0 0

0 0 1 2 4 0

We calculate the following hourglass values:

-63, -34, -9, 12,

-10, 0, 28, 23,

-27, -11, -2, 10,

9, 17, 25, 18

Our highest hourglass value is 28 from the hourglass:

0 4 3

1

8 6 6

Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge.

Function Description

Complete the function hourglassSum in the editor below. It should return an integer, the maximum hourglass sum in the array.

hourglassSum has the following parameter(s):

arr: an array of integers

Input Format

Each of the 6 lines of inputs arr[i] contains 6 space-separated integers arr[i][j].

Constraints

Output Format

Print the largest (maximum) hourglass sum found in .

Sample Input

1 1 1 0 0 0

0 1 0 0 0 0

1 1 1 0 0 0

0 0 2 4 4 0

0 0 0 2 0 0

0 0 1 2 4 0

Sample Output

19

Explanation

contains the following hourglasses:

The hourglass with the maximum sum () is:

2 4 4

2

1 2 4

int hourglassSum(vector<vector<int> > arr) {

int i,j,k,sum,max,count=0;

for(i=0;i<4;i++)

{

for(j=0;j<4;j++)

{

sum=0;

for(k=j;k<j+3;k++)

{

sum+=arr[i][k];

sum+=arr[i+2][k];

}

sum+=arr[i+1][j+1];

if(count==0)

{

max=sum;

count++;

}

else

{

if(max<sum)

max=sum;

}

}

}

return max;

}

please tell me what's wrong with my code?| Flag | PURGE - 1 Answer
**minimize digitsum**You are given positive integers N and D. You may perform operations of the following two types:

- ceaser October 19, 2018

add D to N, i.e. change N to N+D

change N to digitsum(N)

Here, digitsum(x) is the sum of decimal digits of x. For example, digitsum(123)=1+2+3=6, digitsum(100)=1+0+0=1, digitsum(365)=3+6+5=14.

You may perform any number of operations (including zero) in any order. Please find the minimum obtainable value of N and the minimum number of operations required to obtain this value.

this is my code I am getting the wrong answer in some test cases please let me know where I am wrong.

#include<iostream>

#include<queue>

using namespace std;

void check(long long int a, long long int &b, long long int &c, long long int d)

{

if(a<b)

{

b = a;

c = d;

}

}

int digitSum(long long int a)

{

int num = 0;

while(a>0)

{

num += a%10;

a = a/10;

}

return num;

}

void func(int N, int D, long long int &minElement, long long int &minTrial)

{

queue<long long int> q;

q.push(N);

if(N==1)

{

minElement = 1;

minTrial = 0;

}

long long int countNodes = q.size();

long long int level = 1;

int cnt = 1;

while(!q.empty())

{

countNodes = q.size();

while(countNodes>0)

{

long long int temp = q.front();

q.pop();

long long int first = temp+D;

check(first,minElement,minTrial,level);

if(minElement == 1)

{

return;

}

q.push(first);

long long second = digitSum(temp);

check(second,minElement,minTrial,level);

if(minElement == 1)

{

return;

}

q.push(second);

countNodes--;

cnt++;

if(cnt>1000000)

{

break;

}

}

if(cnt>1000000)

{

break;

}

level++;

}

}

int main()

{

long long int t = 1;

cin>>t;

while(t--)

{

long long int N, D;

cin>>N>>D;

long long int minElement = 1e18, minTrial = 1e18;

func(N,D,minElement, minTrial);

cout<<minElement<<" "<<minTrial<<endl;

}

return 0;

}| Flag | PURGE - 1 Answer
**globally unique identifier(GUID)**how to generate GUID in c/c++

- coder September 07, 2018| Flag | PURGE - 0 Answers
**Conversion of Java to C++**How can I convert Java source code into C/C++?

- suhara July 13, 2018| Flag | PURGE - 0 Answers
**Conversion of Java to C++**How can I convert Java source code into C/C++?

- suhara July 13, 2018| Flag | PURGE

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