Skip to main content

Posts

Microsoft CoCubes Java Programming Question – 1 Printing all the Leaders in an Array

  Microsoft CoCubes Java Programming Question – 1 Printing all the Leaders in an Array Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example int the array {16, 19, 4, 3, 8, 3}, leaders are 19, 8 and 3?   Program :   // Microsoft CoCubes Java Programming Question – 1   class LeadersInArray {   void printLeaders (int arr[], int size)   {      for (int i = 0; i < size; i++)     {             int j;             for (j = i + 1; j < size; j++)                 {                     if (arr[i] ...

TCS Coding Question Day 1 Slot 2 – Question 1

  TCS Coding Question Day 1 Slot 2 – Question 1                 Given an integer array Arr of size N the task is to find the count of elements whose value is greater than all of its prior elements. Note :  1st element of the array should be considered in the count of the result. For example, Arr[]={7,4,8,2,9} As 7 is the first element, it will consider in the result. 8 and 9 are also the elements that are greater than all of its previous elements. Since total of  3 elements is present in the array that meets the condition. Hence the output = 3. Example 1: Input  5 -> Value of N, represents size of Arr 7-> Value of Arr[0] 4 -> Value of Arr[1] 8-> Value of Arr[2] 2-> Value of Arr[3] 9-> Value of Arr[4] Output : 3 Example 2: 5   -> Value of N, represents size of Arr 3  -> Value of Arr[0] 4 -> Value of Arr[1] 5 -> Value of Arr[...

TCS NQT Coding Question 2022 – September Day 1 – Slot 1

  TCS NQT Coding Question 2022 – September Day 1 – Slot 1 Problem Statement –  Given a string S(input consisting) of ‘*’ and ‘#’. The length of the string is variable. The task is to find the minimum number of ‘*’ or ‘#’ to make it a valid string. The string is considered valid if the number of ‘*’ and ‘#’ are equal. The ‘*’ and ‘#’ can be at any position in the string. Note :  The output will be a positive or negative integer based on number of ‘*’ and ‘#’ in the input string. ·             (*>#): positive integer ·             (#>*): negative integer ·             (#=*): 0 Example 1: Input 1: ·             ###***   -> Value of S Output : ·             0   → n...

TCS NQT Coding Question 2022 – September Day 1 – Slot 1

  TCS NQT Coding Question 2022 – September Day 1 – Slot 1   Problem Statement –   An automobile company manufactures both a two wheeler (TW) and a four wheeler (FW). A company manager wants to make the production of both types of vehicle according to the given data below: ·             1st data, Total number of vehicle (two-wheeler + four-wheeler)=v ·             2nd data, Total number of wheels = W The task is to find how many two-wheelers as well as four-wheelers need to manufacture as per the given data. Example : Input : 200  -> Value of V 540   -> Value of W Output : TW =130 FW=70 Explanation: 130+70 = 200 vehicles (70*4)+(130*2)= 540 wheels Constraints : ·             2<=W ·             W%2=0 · ...

HackerRank Java Coding Questions and Answers - Guess the word

  HackerRank     Java   Coding   Questions   and   Answers Guess the word 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 below c...

HackerRank Java Coding Questions and Answers - Disk Space Analysis

  HackerRank   Java   Coding   Questions   and   Answers Disk Space Analysis 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] 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   Program :   // Hackerrank Java Coding Questions and Answers //   Disk Space Analysis   import java.util.*; class DiskSpace {   public static void main(String[] args) {   Scanner sc=new Scanner(System.in);   System.out.println...

HackerRank Java Coding Questions and Answers - Astronomy Lecture

  HackerRank   Java   Coding   Questions   and   Answers Astronomy Lecture Problem Statement -: Anirudh is attending an astronomy lecture. His professor who is very strict asks students to write a program to print the trapezium pattern using stars and dots as shown below . Since Anirudh is not good in astronomy can you help him? Sample Input: N = 3 Output: **.** *…* ….. *…* **.** Program :   // Hackerrank Java Coding Questions and Answers //   Astronomy Lecture   import java.util.*; class Trapezium {   public static void main(String[] args) {   Scanner sc=new Scanner(System.in);   int n=sc.nextInt();   int i,j;    for(i=0;i<n;i++)     {         for(j=0;j<n;j++)         {             if(j<n-i-1)   ...