| Assessment Metric | Details |
|---|---|
| Company | IBM India |
| Role | Application developer-Cloud fullstack |
| Duration | 60 Minutes |
| Platform | HackerRank |
| Total Problems | 2 |
In a cloud computing platform, there are virtual machine (VM) types. The number of available instances for each type is given in an array vmStock of size .
Each customer rents exactly one VM. The price paid is the current available instance count of the chosen VM type at that moment. Customers arrive sequentially ( customers total).
Each customer always selects the VM type that is currently most expensive, meaning the type with the highest remaining stock. If multiple VM types tie for highest stock, any of them may be chosen. After a VM is rented, that chosen VM type's stock decreases by .
Compute the total maximum revenue earned after serving all customers.
vmStock.vmStock[i].Input:
4
2
1
1
3
4Output:
8Explanation:
[2, 1, 1, 3]3 (Cost = 3), remaining stock: [2, 1, 1, 2]2 (Cost = 2), remaining stock: [1, 1, 1, 2]2 (Cost = 2), remaining stock: [1, 1, 1, 1]1 (Cost = 1), remaining stock: [0, 1, 1, 1]Input:
3
10
10
11
3Output:
31Explanation:
11 (Cost = 11), remaining stock: [10, 10, 10]10 (Cost = 10), remaining stock: [9, 10, 10]10 (Cost = 10), remaining stock: [9, 9, 10]import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'maximizeRentalRevenue' function below.
*
* The function is expected to return a LONG.
* The function accepts following parameters:
* 1. INTEGER_ARRAY vmStock
* 2. INTEGER m
*/
public static long maximizeRentalRevenue(List<Integer> vmStock, int m) {
// Write your code here
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int vmStockCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> vmStock = IntStream.range(0, vmStockCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int m = Integer.parseInt(bufferedReader.readLine().trim());
long result = Result.maximizeRentalRevenue(vmStock, m);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}Given an array of integers, determine whether the array is ODD, EVEN, or NEUTRAL using the following calculations (the symbol % denotes the modulo operator):
Compute using elements at even indices ():
Compute using elements at odd indices ():
Classification:
"ODD"."EVEN"."NEUTRAL".Input:
6
12
3
6
7
13
12Output:
NEUTRALExplanation:
"NEUTRAL".import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'pluwult' function below.
*
* The function is expected to return a STRING.
* The function accepts INTEGER_ARRAY A as parameter.
*/
public static String pluwult(List<Integer> A) {
// Write your code here
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int aCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> A = IntStream.range(0, aCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
String result = Result.pluwult(A);
bufferedWriter.write(result);
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}