IBM India Online Assessment (OA) | Application developer-Cloud fullstack

Overview

Assessment MetricDetails
CompanyIBM India
RoleApplication developer-Cloud fullstack
Duration60 Minutes
PlatformHackerRank
Total Problems2

Problem 1: Maximize Rental Revenue

Problem Statement

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.

Constraints

Input Format

  • The first line contains an integer , denoting the number of elements in vmStock.
  • Each line of the subsequent lines contains an integer, vmStock[i].
  • The last line contains an integer , denoting the total number of customers.

Sample Cases

Sample 0

Input:

4
2
1
1
3
4

Output:

8

Explanation:

  • Initial stock: [2, 1, 1, 3]
  • Customer 1 picks stock 3 (Cost = 3), remaining stock: [2, 1, 1, 2]
  • Customer 2 picks stock 2 (Cost = 2), remaining stock: [1, 1, 1, 2]
  • Customer 3 picks stock 2 (Cost = 2), remaining stock: [1, 1, 1, 1]
  • Customer 4 picks stock 1 (Cost = 1), remaining stock: [0, 1, 1, 1]
  • Total revenue: .

Sample 1

Input:

3
10
10
11
3

Output:

31

Explanation:

  • Customer 1 picks stock 11 (Cost = 11), remaining stock: [10, 10, 10]
  • Customer 2 picks stock 10 (Cost = 10), remaining stock: [9, 10, 10]
  • Customer 3 picks stock 10 (Cost = 10), remaining stock: [9, 9, 10]
  • Total revenue: .

Template Code

Java
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();
    }
}

Problem 2: plusMult (pluwult)

Problem Statement

Given an array of integers, determine whether the array is ODD, EVEN, or NEUTRAL using the following calculations (the symbol % denotes the modulo operator):

  1. Compute using elements at even indices ():

    • Starting with , alternate between multiplying and adding subsequent even-indexed elements, and evaluate the final result modulo 2:
  2. Compute using elements at odd indices ():

    • Starting with , alternate between multiplying and adding subsequent odd-indexed elements, and evaluate the final result modulo 2:
  3. Classification:

    • If , return "ODD".
    • If , return "EVEN".
    • If , return "NEUTRAL".

Constraints

  • (or )

Input Format

  • The first line contains an integer , denoting the size of array .
  • Each line of the subsequent lines contains an integer, .

Sample Cases

Sample 0

Input:

6
12
3
6
7
13
12

Output:

NEUTRAL

Explanation:

  • Even-indexed elements:
  • Odd-indexed elements:
  • Since and , "NEUTRAL".

Template Code

Java
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();
    }
}
Comments (1)