Monday, September 7, 2020

Hackerrank :- Hackerland Radio Transmitters solution in c#

 Hackerland is a one-dimensional city with houses aligned at integral locations along a road. The Mayor wants to install radio transmitters on the roofs of the city's houses. Each transmitter has a fixed range meaning it can transmit a signal to all houses within that number of units distance away.

Given a map of Hackerland and the transmission range, determine the minimum number of transmitters so that every house is within range of at least one transmitter. Each transmitter must be installed on top of an existing house.

For example, assume houses are located at  and the transmission range  antennae at houses  and  and  would provide complete coverage. There is no house at location  to cover both  and . Ranges of coverage, are , and .

Function Description

Complete the hackerlandRadioTransmitters function in the editor below. It must return an integer that denotes the minimum number of transmitters to install.

hackerlandRadioTransmitters has the following parameter(s):

  • x: integer array that denotes the locations of houses
  • k: an integer that denotes the effective range of a transmitter

Input Format

The first line contains two space-separated integers  and , the number of houses in Hackerland and the range of each transmitter.
The second line contains  space-separated integers describing the respective locations of each house .

Constraints

  • There may be more than one house at the same location.

Subtasks

  •  for  of the maximum score.

Output Format

Print a single integer denoting the minimum number of transmitters needed to cover all of the houses.

Sample Input 0

5 1
1 2 3 4 5

Sample Output 0

2

Explanation 0

The diagram below depicts our map of Hackerland:

k-nearest(2).png

We can cover the entire city by installing  transmitters on houses at locations  and .

Sample Input 1

8 2
7 2 4 6 5 9 12 11 

Sample Output 1

3

Explanation 1

The diagram below depicts our map of Hackerland:

k-nearest2(2).png

We can cover the entire city by installing  transmitters on houses at locations , and .

Solution :- 

// Complete the hackerlandRadioTransmitters function below.
    static int hackerlandRadioTransmitters(int[] x, int k) {
     Array.Sort(x);
            var count = 0;
            var i = 0;
            while(x.Length > i)
            {
                count++;
                var loc = x[i] + k;
                while (i < x.Length && x[i] <= loc)
                    i++;
                i--;

                loc = x[i] + k;
                while (i < x.Length && x[i] <= loc)
                    i++;
            }
            return count;
    
    }




Hackerrank :- Ice Cream Parlor problem in c#

 Sunny and Johnny like to pool their money and go to the ice cream parlor. Johnny never buys the same flavor that Sunny does. The only other rule they have is that they spend all of their money.

Given a list of prices for the flavors of ice cream, select the two that will cost all of the money they have.

For example, they have  to spend and there are flavors costing . The two flavors costing  and  meet the criteria. Using -based indexing, they are at indices  and .

Function Description

Complete the icecreamParlor function in the editor below. It should return an array containing the indices of the prices of the two flavors they buy, sorted ascending.

icecreamParlor has the following parameter(s):

  • m: an integer denoting the amount of money they have to spend
  • cost: an integer array denoting the cost of each flavor of ice cream

Input Format

The first line contains an integer, , denoting the number of trips to the ice cream parlor. The next  sets of lines each describe a visit. Each trip is described as follows:

  1. The integer , the amount of money they have pooled.
  2. The integer , the number of flavors offered at the time.
  3.  space-separated integers denoting the cost of each flavor: .

Note: The index within the cost array represents the flavor of the ice cream purchased.

Constraints

  • , ∀ 
  • There will always be a unique solution.

Output Format

For each test case, print two space-separated integers denoting the indices of the two flavors purchased, in ascending order.

Sample Input

2
4
5
1 4 5 3 2
4
4
2 2 4 3

Sample Output

1 4
1 2

Explanation

Sunny and Johnny make the following two trips to the parlor:

  1. The first time, they pool together  dollars. Of the five flavors available that day, flavors  and  have a total cost of .
  2. The second time, they pool together  dollars. TOf the four flavors available that day, flavors  and  have a total cost of .

Solution :-

// Complete the hackerlandRadioTransmitters function below.
    static int hackerlandRadioTransmitters(int[] x, int k) {
     Array.Sort(x);
            var count = 0;
            var i = 0;
            while(x.Length > i)
            {
                count++;
                var loc = x[i] + k;
                while (i < x.Length && x[i] <= loc)
                    i++;
                i--;

                loc = x[i] + k;
                while (i < x.Length && x[i] <= loc)
                    i++;
            }
            return count;
    
    }


Part 7 — Enterprise RAG Reference Architecture

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