Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /*
- https://www.desiqna.in/16117/paypal-oa-october-2023-break-sort
- */
- /*
- //inputs for array
- 3 25 8
- expected output -
- The result is 2
- */
- @SuppressWarnings("unused")
- public class Zztemp1 {
- static Scanner sc = new Scanner(System.in);
- private static int[] getArray() {
- String[] sArr = sc.nextLine().split(" ");
- int[] arr = Arrays.stream(sArr).mapToInt(Integer::parseInt).toArray();
- return arr;
- }
- private static char[] getCharArray() {
- String[] sArr = sc.nextLine().split(" ");
- char[] cArr = new char[sArr.length];
- for (int i = 0; i < sArr.length; i++) {
- cArr[i] = sArr[i].charAt(0); // Take the first character of each string
- }
- return cArr;
- }
- public static void main(String args[]) {
- // get the inputs from terminal
- int[] A = getArray();
- int arrLen = A.length;
- int rightBigNum = A[arrLen-1];//you cannot do anything with the last digit , you have to follow it
- int breaks = 0;
- for (int i = arrLen-2; i >=0; i-=1) {//traversing from right
- int curr = A[i];
- if (rightBigNum>=curr){//no need to break this abides sorted policy lets go to next taking this as rightBigNum
- rightBigNum = curr;
- }else{
- int parts = (int)(Math.ceil(curr/rightBigNum));
- breaks +=(parts-1);//num of curr breaks is parts-1
- rightBigNum = curr/parts;//this is the max bound for next num which was evenly distributed
- }
- }
- // //prepare the answer
- System.out.println("The result is " +breaks);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement