Hexaware Coding Questions and Answers

Hexaware Coding Questions with Solutions

Here on this page, you will get Hexaware Coding Questions and Answers based on previous years’ patterns in different programming languages.

This page includes the sample questions of Advanced Data Structures and Algorithms with their solutions in different programming languages.

Hexaware Coding Questions 2

Hexaware Coding Questions with Solutions

Q1. Problem Statement

Kochouseph Chittilappilly went to Dhruv Zplanet, a gaming space, with his friends and played a game called “Guess the Word”. 

Rules of games are –

Computer displays some strings on the screen and the player should pick one string/word if this word matches with the random word that the computer picks then the player is declared as Winner.
Kochouseph Chittilappilly’s friends played the game and no one won the game. This is Kochouseph Chittilappilly’s turn to play and he decided to must win the game. 
What he observed from his friend’s game is that the computer is picking up the string whose length is odd and also that should be maximum. Due to system failure computers sometimes cannot generate odd-length words. In such cases, you will lose the game anyways and it displays “better luck next time”. He needs your help. Check the below cases for a better understanding

Sample Input & Output

  • Sample input 0:
    5   → ( number of strings )
    Hello Good morning Welcome you
  • Sample output 0: morning
  • Explanation: First word that is picked by the computer is morning 
    Hello → 5
    Good → 4
    Morning → 7
    Welcome → 7 
    You → 3

 

  • Sample input 1:
    3
    Go to hell 
  • Sample output 1: Better luck next time 
  • Explanation: Here is no word with odd length so computer confuses and gives better luck next time

Use Coupon Code “CT15” and get flat 15% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 6 month plan
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

Q2. Problem Statement

Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.

Note that: Ratan never goes into loss.

  • Example 1:
    Price = [ 1, 6, 2 ]
    Ratan buys it on the first day and sells it on the second. 
  • Example 2:
    Price = [ 9, 8, 6 ] 
    The Price always went down, Ratan never bought it.

Input Format:
First line with an integer n, denoting the number of days with the value of the stack
Next n days, telling the price of the stock on that very day.

Output Format:
Maximum profit done by Ratan in a single line.

Constraints:
Number of days <=10^8

Sample Input for Custom Testing

  • Sample Input: 7, [ 1, 9, 2, 11, 1, 9, 2 ]
  • Sample Output:  10
  • Explanation: The maximum profit possible is when Ratan buys it in 1 rupee and sells it in 11.

Q3. Problem Statement

Frogs are sitting on the x-axis of the plane. The x-axis is represented by a given string. * represents a frog and | represents a stone.
The string consists of only the above-mentioned characters. You are given a start index array and end index array, and calculate the number of frogs between the two stones including the endpoint.
Note – Array is 1 indexed

  • Example:
     s = ” |**|*| ”  
    start Index = [ 1, 1 ]
    end Index = [ 5, 6 ]

For the first pair of indices (1,5), the substrings are “|**|*”. There are 2 stars between a pair of bars. For the second pair of indices (1,6), the substring is  “|**|*|” and there are 2+1=3 stars in between the bars. Both of the answers are returned to the array [2,3].

Constraints

  • 1 <= n <= 105
  • 1 <= Start Index[i] <= end Index[i]
  • Each Character of s is either  ” * ”  or  ” | “

Input Format for Custom testing
First line contains a string S the next line contains an integer n, the no.of elements in startIndex. Each line i of the n subsequent lines contains an integer of the start index. the next line contains an integer n, the no. of elements in end Index. Each line i of the n subsequent lines contains an integer of the end index  

Sample Input for Custom Testing

  • Sample Case 0
    *|*|  → s = ” *|*| ”
    1 → startindex[] size=1
    1 → startindex= 1
    1 → endindex[] size=1
    3 → endindex=3
  • Sample output: 0
  • Explanation: The substring from index =1 to index=3 is “*|*”. there is no consecutive pair of bars in this string.

Use Coupon Code “CT15” and get flat 15% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 6 month plan
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

Q4. Problem Statement

Stephan is a vampire. And he is fighting with his brother Damon. Vampires get energy from human blood, so they need to feed on human blood, killing human beings. Stephan is also less inhuman, so he will like to take less life in his hand. Now all the people’s blood has some power, which increases the powers of the Vampire. Stephan just needs to be more powerful than Damon, killing the least human possible. Tell the total power Stephan will have after drinking the blood before the battle.
Note: Damon is a beast, so no human being will be left after Damon drinks everyone’s blood. But Stephan always comes early to the town.

Input Format:
First line with the number of people in the town, n.
Second line with a string with n characters, denoting the one-digit power in every blood.

Output Format:
Total minimum power Stephan will gather before the battle.

Constraints:
n <= 10 ^ 4

  • Sample Input :
    6
    093212
  • Sample output:
    9
  • Explanation: Stephan riches the town and drinks the blood with power 9. Now Damon cannot reach 9 by drinking all the other blood.

Q5. Problem Statement

There are some groups of devils and they split into people to kill them. Devils make People them left as their group and at last the group with maximum length will be killed. Two types of devils are there namely “@” and “$”. People are represented as a string “P”

Input Format:
First line with the string for input

Output Format:
Number of groups that can be formed.

Constraints:
2<=Length of string<=10^9

  • Input string: PPPPPP@PPP@PP$PP
  • Output: 7
  • Explanation: 4 groups can be formed
    PPPPPP@
    PPP@
    PP$
    PP

Most people in the group lie in group 1 with 7 members.

Q6. Problem Statement

Given a string, return the character that appears the minimum number of times in the string. The string will contain only ASCII characters, from the ranges        ( “a” – “z”, “A” – “Z”, 0 – 9 ), and case matters. If there is a tie in the minimum number of times a character appears in the string return the character that appears first in the string.

Input Format:
Single line with no space denoting the input string.

Output Format:
Single character denoting the least frequent character.

Constraints:
Length of string <=10^6

Sample Input / Output

  • Sample Input: cdadcda
  • Sample Output: c
  • Explanation: C and A both are with minimum frequency. So c is the answer because it comes first with less index.

Use Coupon Code “CT15” and get flat 15% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 6 month plan
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

Q7. Problem Statement

Rohit loves to play with sequences so he has given you a sequence to solve. To prove to him that you are a good coder, you accept the challenge. Find the sum of the sequence. Given three integers i, j, k. Find  i + (i+1) + (i+2) + (i+3) … j + (j-1) + (j-2) + (j-3) …….. k

  • Example:
    i=5
    j=9
    k=6

 Sum of all values from i to j and back to k:  5 + 6 + 7 + 8 + 9 + 8 + 7 + 6 = 56

CONSTRAINTS:
 -108 <= i, j, k <= 108
   i, k <= j

 

  • SAMPLE CASE 0:
     0  → i = 0
     5  → j = 5
    -1  → k = -1
  • SAMPLE OUTPUT 0:  24
  • EXPLANATION 0:  0 + 1 + 2 + 3 + 4 + 5 + 4 + 3 + 2 + 1 + 0 – 1 = 24

Q8. Problem Statement

The principal has a problem with repetitions. Every time someone sends the same email twice he becomes angry and starts yelling. His assistant filters the mails so that all the unique mails are sent only once, and if someone is sending the same mail again and again, he deletes them. Write a program that will see the list of roll numbers of the student and find how many emails are to be deleted.

  • Sample Input:  6,  [ 1, 3, 3, 4, 3, 3 ]
  • Sample Output: 3

Q9. Problem Statement

There is an id code that is supposed to be given to all the aspirants of an exam. It is a substring of a given string. That means, the authority takes a string and then assigns all the unique substrings to all the students. Suppose there is a string “abcde”, so the ids of the students will be “a”, “b”, “c”, “d”, “e”, “ab”, “abc”, “abcd”, “abcde”, ” bc”, “bcd”, “bcde”, “cd”, “cde”, “de”.
The students are standing in a line according to the lexicographic order of their given ids. You have to find out the id of the last student for the given input string from which the ids are generated.

Input Format:
Single line with the id generating string

Output format:
The last id as per lexicographical order

Constraints:
Number of characters in the string<=10^9

  • Sample Input: abdc
  • Sample output: dc
  • Explanation: The last student will be with the id dc. The order will be
    abdc
    a
    ab
    abd
    abdc
    b
    bd
    bdc
    c
    d
    dc

Use Coupon Code “CT15” and get flat 15% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 6 month plan
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

Q10. Problem Statement

You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.

  • Sample Input:
    1 →  Length of segment x =1
    5 →  size of space n = 5
    1 → space = [ 1,2,3,1,2]



  • Sample Output: 3
  • Explanation: The subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3.

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription