Skip to main content

Posts

Showing posts from May, 2022

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)   ...

HackerRank Java Coding Questions and Answers - Network Stream

HackerRank   Java   Coding   Questions   and   Answers Network Stream Problem Statement –  A stream of n data packets arrives at a server. This server can only process packets that are exactly 2^n units long for some non-negative integer value of n (0<=n). All packets are repackaged in order to the 1 largest possible value of 2^n units. The remaining portion of the packet is added to the next arriving packet before it is repackaged. Find the size of the largest repackaged packet in the given stream. Example : arriving Packets = [12, 25, 10, 7, 8] The first packet has 12 units. The maximum value of 2^n that can be made has 2^n = 2^3 = 8 units because the next size up is 2^n = 2^4 = 16 (16 is greater than 12). 12 – 8 = 4 units are added to the next packet. There are 4 + 25 = 29 units to repackage, 2^n = 2^4 = 16 is the new size leaving 9 units (29-16 = 9) Next packet is 9 + 10 = 29 unists & the maximum units(in 2^n) is 16 leaving 3 uni...

HackerRank Java Coding Questions and Answers - Minimum streets lights

HackerRank   Java   Coding   Questions   and   Answers Minimum streets lights Problem Statement -:  Street Lights are installed at every position along a 1-D road of length n. Locations[] (an array) represents the coverage limit of these lights. The ith light has a coverage limit of locations[i] that can range from the position max((i – locations[i]), 1) to min((i + locations[i]), n ) (Closed intervals). Initially all the lights are switched off. Find the minimum number of fountains that must be switched on to cover the road. Example n = 3 locations[] = {0, 2, 13}then For position 1:  locations[1] = 0, max((1 – 0), 1) to mini (1+0), 3) gives range = 1 to 1 For position 2:  locations[2] = 2, max((2-2), 1) to min( (2+2), 3) gives range = 1 to 3 For position 3:  locations[3] = 1, max( (3-1), 1) to min( (3+1), 3) gives range = 2 to 3 For the entire length of this road to be covered, only the light at position 2 needs to ...

Python Project With Source Code : Password Generator

  Password Generator import random   def generatePassword(pwlength):       alphabet = "abcdefghijklmnopqrstuvwxyz"       passwords = []       for i in pwlength:                 password = ""         for j in range(i):             next_letter_index = random.randrange(len(alphabet))             password = password + alphabet[next_letter_index]                 password = replaceWithNumber(password)         password = replaceWithUppercaseLetter(password)                 passwords.append(password) ...