BUG-D-CODE

Round 2 closed.

  • submit here 
  • Second Set: This is the second set of questions.
    You guys have 30 minutes to solve these!


    • Question 1: Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
      Then print the respective minimum and maximum values as a single line of two space-separated long integers.

      For example, if the array arr = [1,3,5,7,9]. Our minimum sum is 1+3+5+7=16 and our maximum sum is 3+5+7+9=24.

      We would print 16 24

    • Question 2: Given a time in -hour AM/PM format, convert it to military (24-hour) time.

      Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.

    • Question 3: Dan is playing a video game in which his character competes in a hurdle race.
      Hurdles are of varying heights, and Dan has a maximum height he can jump.
      There is a magic potion he can take that will increase his maximum height by 1 unit for each dose.
      How many doses of the potion must he take to be able to jump all of the hurdles.

      Given an array of hurdle heights height, and an initial maximum height Dan can jump, k, determine the minimum number of doses Dan must take to be able to clear all the hurdles in the race.

      For example, if height=[1,2,3,3,2] and Dan can jump 1 unit high naturally, he must take 3-1 =2 doses of potion to be able to jump all of the hurdles

    • Question 4: Given an array of integers, find and print the maximum number of integers you can select from the array such that the absolute difference between any two of the chosen integers is less than or equal to 1.

      For example, if your array is a=[1,1,2,2,4,4,5,5,5], you can create two subarrays meeting the criterion: and [4,4,5,5,5] .

      The maximum length subarray has 5 elements.

    • Question 5: John Watson knows of an operation called a right circular rotation on an array of integers.
      One rotation operation moves the last array element to the first position and shifts all remaining elements right one. To test Sherlock's abilities, Watson provides Sherlock with an array of integers.
      Sherlock is to perform the rotation operation a number of times then determine the value of the element at a given position.

      For each array, perform a number of right circular rotations and return the value of the element at a given index.

      For example, array a=[3,4,5] , number of rotations k=2, and indices to check,m=[1,2]. First we perform the two rotations: [3,4,5] -> [5,3,4] -> [4,5,3] Now return the values from the zero-based indices 1 and 2 as indicated in the m array.