Monday, September 7, 2020

HackerRank :- Jumping on the Clouds solution in c#

 Emma is playing a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. She can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus  or . She must avoid the thunderheads. Determine the minimum number of jumps it will take Emma to jump from her starting postion to the last cloud. It is always possible to win the game.

For each game, Emma will get an array of clouds numbered  if they are safe or  if they must be avoided. For example,  indexed from . The number on each cloud is its index in the list so she must avoid the clouds at indexes  and . She could follow the following two paths:  or . The first path takes  jumps while the second takes .

Function Description

Complete the jumpingOnClouds function in the editor below. It should return the minimum number of jumps required, as an integer.

jumpingOnClouds has the following parameter(s):

  • c: an array of binary integers

Input Format

The first line contains an integer , the total number of clouds. The second line contains  space-separated binary integers describing clouds  where .

Constraints

Output Format

Print the minimum number of jumps needed to win the game.

Sample Input 0

7
0 0 1 0 0 1 0

Sample Output 0

4

Explanation 0:
Emma must avoid  and . She can win the game with a minimum of  jumps:

Sample Input 1

6
0 0 0 0 1 0

Sample Output 1

3

Explanation 1:
The only thundercloud to avoid is . Emma can win the game in  jumps:

Solution :-

 // Complete the jumpingOnClouds function below.
    static int jumpingOnClouds(int[] c) {
 var count = 0;
            for(var i = 0; i < c.Length-1;)
            {
                if (c.Length > (i + 2) && c[i + 2] == 0)
                {
                    ++count;
                    i = i + 2;
                    continue;
                }
                else if (c.Length > (i + 1) && c[i + 1] == 1)
                    break;
                ++count;
                ++i;
            }
            return count;

    }




Hackerrank :- Birthday Cake Candles solution in c#

 You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example

The maximum height candles are  units high. There are  of them, so return .

Function Description

Complete the function birthdayCakeCandles in the editor below.

birthdayCakeCandles has the following parameter(s):

  • int candles[n]: the candle heights

Returns

  • int: the number of candles that are tallest

Input Format

The first line contains a single integer, , the size of .
The second line contains  space-separated integers, where each integer  describes the height of .

Constraints

Sample Input 0

4
3 2 1 3

Sample Output 0

2

Explanation 0

Candle heights are . The tallest candles are  units, and there are  of them.

Solution :-

 // Complete the birthdayCakeCandles function below.
    static int birthdayCakeCandles(int[] arr) {

 var maxNum = 0;
            var i  = 0;
            var list = new Dictionary<int, int>();
            while (arr.Length > i)
            {
                if (i == 0)
                {
                    maxNum = arr[i];
                    list.Add(maxNum, 1);
                }
                else
                {
                     if(arr[i] > maxNum)
                        maxNum = arr[i];
                    if (list.ContainsKey(arr[i]))
                    {
                        list[arr[i]] = list[arr[i]] + 1;
                    }
                    else
                        list.Add(arr[i], 1);
                }
                i++;
            }

            return list[maxNum];
    }



Part 7 — Enterprise RAG Reference Architecture

  "Architecture is not about connecting components. It is about defining responsibilities that can evolve independently." Welcome ...