Posts

Showing posts with the label SOLUTION

Important TCS CodeVita Questions Solved – Sheldon Cooper and his beverage paradigm

Image
Important TCS CodeVita Questions Solved – 2015 Problem : Sheldon Cooper and his beverage paradigm Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, To decide the amount of beverage they plan to consume, say X. Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively. If quantity of any three drinks add up to X then we’ll have it else we’ll return the order. E.g. If a + d + f = X then True else False You are given Number of bottles N corresponding to different beverages and hence their sizes Next N lines, contain a positive integer corresponding to the size of the beverage Last line consists of an integer value, denoted by X above Your task is to help find out if there can be any combination of three beverage sizes that can sum up to the quantity they intend to consume. If such a combination...

TCS Codevita Minimum Distance Solution

Image
Problem : Minimum Distance Two riders A and B are travelling on a highway towards each other on two roads that intersect at right angle at speeds  V A meters/second and  V B  meters/second. A is at a distance of  'x'  meters and B is at a distance of  'y'  meters from the intersection. Calculate the minimum distance between these two riders that is possible.                                                               Fig:Approaching Intersection Input Format: First line contains the distance of Rider A from intersection denoted by x Second line contains the distance of Rider B from intersection denoted by y Third line contains the Vel...

TCS Codevita Reverse Gear Solution

Problem : Reverse Gear A futuristic company is building an autonomous car. The scientists at the company are training the car to perform Reverse parking. To park, the car needs to be able to move in backward as well as forward direction. The car is programmed to move backwards B meters and forwards again, say F meters, in a straight line. The car does this repeatedly until it is able to park or collides with other objects. The car covers 1 meter in T units of time. There is a wall after distance D from car's initial position in the backward direction. The car is currently not without defects and hence often hits the wall. The scientists are devising a strategy to prevent this from happening. Your task is to help the scientists by providing them with exact information on amount of time available before the car hits the wall. Input Format: First line contains total number of test cases, denoted by N Next N lines, contain a tuple containing 4 values delimited by space ...

TCS Codevita Credit and Risk Calculator Solution

Problem : Credit and Risk Calculator Money Bank is an investment bank. It gives money to the companies for their operation that approach it. The bank's officers have to calculate the maximum amount that the company can be given, based on the company's market value and its market rating published by Global Rating Companies. The maximum amount will change on a daily basis as per the change in the company's shares, its market value and its change in rating. Based on the maximum amount allocated, the bank internally calculates the amount that the company can use on a particular day. The maximum amount that the bank will give at any point is 50% of the company's value, which will decrease as per the change in the company's rating. Example: Company ABC has 25734 shares in the market. The current value of the share is 77 INR. The change in the Share Value from yesterday is +10(or 10) Today's rating of ABC is 87 (out of 100). The change in rating from yesterday i...

TCS Codevita N Queen Problem with Solution

Image
Problem : Given a n x n grid, how would you place n queens so that no two are attacking. Two queens are said to be attacking if they are on same row, column or diagonal. The naive solution of this problem will require to find  all the permutations i.e. finding all the n! arrangements. A typical example of n queen problem is 8 queen problem which requires us to find possible placements of 8 queens on a 8 x 8 chess board. One of the arrangements of 8 x 8 problem is shown below :  Placements of 8 queens over 8 x 8 chess board Solution of this problem can be thought as follows: We start from first row and proceed to next row till last row. if next queen to be placed has same column value as already placed queen has then don't place the queen. This can be checked by traversing from i=1 to i= k-1 where k is the next row where queen is to be placed. if next queen to be placed lies in any of the diagonals of already placed queens then don't place the queen. This can be do...

Wanna Cry Ransomware Prevention and Anti virus

Image
Hello Friends,                       Here is the Good News about Antivirus Protection. There is an Antivirus Available.So Just Calm Down and Install the best Security Provided By Sophos  .We have a solution . A Hack So Enjoy.But Be Safe. Click Here To Download Antivirus Software to prevent Ransomeware. Check How Sophos Stops wanna Cry Virus. YouTube https://www.youtube.com/watch?v=agFgibQydzg

TCS CodeVita 2016 Round1 Question: Consecutive Prime Sum

Image
Problem : Consecutive Prime Sum Some prime numbers can be expressed as Sum of other consecutive prime numbers. For example 5 = 2 + 3 17 = 2 + 3 + 5 + 7 41 = 2 + 3 + 5 + 7 + 11 + 13 Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2. Write code to find out number of prime numbers that satisfy the above mentioned property in a given range. Input Format: First line contains a number N Output Format: Print the total number of all such prime numbers which are less than or equal to N. Constraints: 1. 2 Sample Input and Output SNo. Input Output Comment 1 20 2 (Below 20, there are 2 such numbers: 5 and 17). 5=2+3 17=2+3+5+7 2 15 1 Pseudo Code: 1. Find all the prime numbers till N     i.  A  is an array length N + 1 initialized with numbers from 0 to N                 ...

TCS CodeVita 2016 Round1 Question: Min Product Array

Image
The task is to find the minimum sum of Products of two arrays of the same size, given that k modifications are allowed on the first array. In each modification, one array element of the first array can either be increased or decreased by 2. Note - the product sum is Summation (A[i]*B[i]) for all i from 1 to n where n is the size of both arrays Input Format:   First line of the input contains n and k delimited by whitespace Second line contains the Array A (modifiable array) with its values delimited by spaces Third line contains the Array B (non-modifiable array) with its values delimited by spaces Output Format: Output the minimum sum of products of the two arrays Constraints: 1 ≤ N ≤ 10^5 0 ≤ |A[i]|, |B[i]| ≤ 10^5 0 ≤ K ≤ 10^9 Sample Input and Output SNo. Input Output 1 3 5 1 2 -3 -2 3 -5 -31 2 5 3 2 3 4 5 4 3 4 2 3 2 25 Explanation for sample 1: Here total numbers are 3 and total modifications allowed are 5. So we modified A[2], which is ...