Hexaware Live Session Part 2
Hexaware Live Session Part 2
Value of Cards
You are given a function, int GetTotalPoints(int a, int b, int c, int d);
The function accepts integers a, b, c, d as inputs. Cards of deck are represented as follows,
{Ace:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, Jack:11, Queen:12, King:13}. a, b, c, d forms a set of 4 cards of a deck.
In a card game called ‘Twenty-Nine’, the points associated with each card is:
● Face card Jack card have 3 points each
● Cards with the number 9 have 2 points each
● Aces have 1 point each
● Cards with the number 10 have 1 point each
● Rest of the cards have value of 0 point each
Implement the function to compute and return the total points of given set of cards, by adding the points associated
with each card.
Note: 1<= a, b, c, d <= 13
Explanation:
Example:
Set of cards:
Input:
● 11 represents a Jack
11
● 9 represents a 9 numbered card
9
● 1 represents Ace
1
● 5 represents a 5 numbered card
5
Values:
Output:
● The equivalent value of 11(Jack) is 3
6
● The equivalent value of 9 is 2
3+2+1+0 = 6 (output)
● The equivalent value of 1 is 1
● The equivalent value of 5 is 0
● 3+2+1+0 = 6 (output)
Case 1 Case 3
Input (stdin) Input (stdin)
11 10
9 11
1 12
5 13
Output (stdout) Output (stdout)
6 4
Case 2 Case 4
Input (stdin) Input (stdin)
1 1
2 9
3 10
4 11
Output (stdout) Output (stdout)
1 7
Problem Statement:
Polygon: A Polygon is a closed figure composed of three or more Line segments, in which its longest side is smaller the sum of its other sides. You are
given an array of size n named sides. find the polygon with the largest Perimeter that can be formed from given side and print the perimeter of the same.
Note:
3. if a polygon cannot be formed from the given sides, then print -1.
Input format:
2. The second line consist of N space separated integers denoting the away sides.
Output format:
Constraints:
0<n<= 10^4
Input:
7
1 12 3 2 5 1 50
Output: 12
Input:
5
50 1 2 2 50
Output: 105
Problem Statement:
Maximum Subarray
Given an Integer array, find the maximum sum contiguous subarray. If the array contains all negative numbers, then the
maximum subarray contains only the negative numbers with the least value.
Input Specification:
Input1: N, the number of elements in an array
Input2: Array of numbers
Output Specification:
Return the maximum sum of contiguous elements.
Example1:
Input1: 3
Input2: {3, -1, 2}
Output: 4
Explanation:
The maximum number in the given array is 3, but if we add all the elements of the array 3-1+2, we get the output as 4.
Case 1
Case 3 Case 5
Input (stdin)
Input (stdin) Input (stdin)
3
3 2
3
1 9
-1
1 -1
2 Output (stdout)
1
Output (stdout)
Output (stdout) 9
4
3
Case 2
Case 4
Input (stdin)
Input (stdin)
8
4
-2
-1
-3
1
4
2
-1
3
-2 Output (stdout)
1 6
5
-3
Output (stdout)
7
Problem Statement:
Planning the Street
King George has built an exclusive street for his executive class employees to build their homes. The street is divided
into M sections. Each section corresponds to two plots, one on each side of the street. Find the number of possible
assignments.
He has assigned you to plan that street .You have to decide on which plots along the street it is allowed to build new
buildings. In order to do this, you want to first calculate the number of possible ways of assigning free plots to buildings
with the restriction that no two consecutive plots exist on which it is allowed to build - you want to give the inhabitants
the feeling that they have more free room so that they can live happily.
Input: 3
An integer M denoting the number of sections.
Output: 25
Number of possible assignments
Explanation:
If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX,
YXY, YYX, XYY, YYY.
Since the same number exists on the other side, we have 5*5 = 25 combinations.
Case 1
Input (stdin)
3 Case 4
Output (stdout)
Input (stdin)
25
4
Output (stdout)
Case 2 64
Input (stdin)
2 Case 5
Output (stdout)
Input (stdin)
9
5
Output (stdout)
Case 3 169
Input (stdin)
1
Output (stdout)
4
Problem Statement:
Write a program to take two integers m & n as input and find the number of possible sequences of length n such that
each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
Input:
10
4
Output:
4
Explanation:
There should be n elements and value of last element should be at-most m.
The sequences are {1, 2, 4, 8}, {1, 2, 4, 9}, {1, 2, 4, 10}, {1, 2, 5, 10}
Case 1
Input (stdin)
10
4
Output (stdout) Case 4
4 Input (stdin)
6
Case 2 3
Input (stdin) Output (stdout)
2 4
1
Output (stdout)
2 Case 5
Input (stdin)
Case 3 6
Input (stdin) 2
5 Output (stdout)
2 9
Output (stdout)
6
Problem Statement:
Straight Line or 0
Given a set of points in a plane, check whether the points lie on a straight line or not. If they lie on a straight line returns
1, else return 0.
Input specification:
Input 1: First Line contains no of points in the plane.
Input 2: Second line contains x,y coordinates of all the points which are divided with spaces.
Output Specification:
1 (str) if the points lie on a plane or 0(str).
Sample Input:
3
112233
Output:
1
Explanation:
The three points here are [1,1],[2,2] and [3,3]. These lie on a line so it returns 1.
Case 1 Case 3 Case 5
Input (stdin) Input (stdin) Input (stdin)
1 1 11
1 2 22
2 3 33
2 5 55
3 5 66
3 9 77
Output (stdout) Output (stdout) Output (stdout)
1 0 0
Case 2 Case 4
Input (stdin) Input (stdin)
1 11
2 2
3 33
4 5
5 5
6 93
Output (stdout) Output (stdout)
1 0