πŸ“˜
Placecom Question
  • βœ…ABC? (Contest)
  • βœ…Activity Selection (Contest)
  • βœ…Absolute value discrepancy (Contest)
  • βœ…Akash's Contest (Contest)
  • βœ…Alternate Matrix Addition(Contest)
  • βœ…Anti clockwise(Contest)
  • βœ…Arpit's toy (Contest)
  • βœ…Array Frequency Paradigm (Contest)
  • βœ…Array Games (Contest)
  • βœ…Arranging Students (Contest)
  • βœ…Array Proximity (Contest)
  • βœ…ATM Machine (Contest)
  • βœ…Awesome Numbers(Contest)
  • βœ…Bad Dish (Contest)
  • βœ…Balanced Neighborhood (Contest)
  • βœ…Birthday Gift (Contest)
  • βœ…Boundary Traversal of Matrix(Contest)
  • βœ…Buy and Sell Stock(Contest)
  • βœ…Cakewalk? (Contest)
  • βœ…Can we sort? (Contest)
  • βœ…Candy Love (Contest)
  • βœ…Candy Shopping (Contest)
  • βœ…Choose Card optimally(Contest)
  • βœ…Candy Store Earnings (Contest)
  • βœ…Choose points (Contest)
  • βœ…Concatenate Strings (Contest)
  • βœ…Common digits in two numbers (Contest)
  • βœ…Count 1's in binary array(Contest)
  • βœ…Count Numbers (Contest)
  • βœ…Count Total Digits in a Number (Contest)
  • βœ…Counting Zeroes to Ones (Contest)
  • βœ…Cyclic Rotation Paradigm (Contest)
  • βœ…Derrangement Exercise (Contest)
  • βœ…Diagonal Sum(Contest)
  • βœ…Diet planning (Contest)
  • βœ…Difference Array (Contest)
  • βœ…Digits Rearrangement (Contest)
  • ❌Divisible by 8 (Contest)
  • βœ…Door problem (Contest)
  • βœ…Duplicates at a distance k (Contest)
  • βœ…Easy - Peasy (Contest)
  • βœ…Eat or be Eaten(Contest)
  • βœ…Factorial - Recursion(Contest)
  • βœ…Find element in 2D array (Contest)
  • βœ…Generate all parentheses(Contest)
  • βœ…The gabba test(Contest)
  • βœ…Fruit Market (Contest)
  • βœ…Frequency Sort (Contest)
  • βœ…Floor in a Sorted Array(Contest)
  • βœ…First non-repeating character in a String(Contest)
  • βœ…Find unique(Contest)
  • βœ…Get the Shadow (Contest)
  • βœ…Good cells (Contest)
  • βœ…Good circular array (Contest)
  • βœ…Grid Magic (Contest)
  • βœ…Guardians of Galaxy(Contest)
  • βœ…Happy Balloons (Contest)
  • βœ…Help James (Contest)
  • βœ…Help Samar with Chopsticks (Contest)
  • βœ…Hip Hip Array (Contest)
  • βœ…Increment- Decrement Philosophy (Contest)
  • βœ…Infinity Stones : Form Black Order - The Army of Thanos (Contest)
  • βœ…Insert Operator(Contest)
  • βœ…Integer Modification (contest)
  • βœ…Inversion of array(Contest)
  • βœ…Iso Lexo String (Contest)
  • βœ…Jumping Numbers (Contest)
  • βœ…K closest points(Contest)
  • βœ…Knight game(Contest)
  • βœ…K-Pairs (Contest)
  • βœ…Kth Row of Pascal's Triangle(Contest)
  • βœ…Largest Bitonic Subarray(Contest)
  • βœ…Least Subarrays(Contest)
  • βœ…Lexographical Rotation (Contest)
  • βœ…Lone Sum Supremacy (Contest)
  • βœ…Lucky Boys(Contest)
  • ❌Majority Element(Contest)
  • βœ…Matrix problem(Contest)
  • βœ…Matrix ZigZag Traversal(Contest)
  • βœ…Max Candies(Contest)
  • βœ…Max permute (Contest)
  • βœ…Max Score in Quiz (Contest)
  • βœ…Max sum column (Contest)
  • βœ…Max XOR(Contest)
  • ❌Maximize Strength (Contest)
  • βœ…Maximizing Difference(Contest)
  • βœ…Maximum Area(Contest)
  • ❌Maximizing Difference(Contest)
  • βœ…Maximum Force(Contest)
  • βœ…Longest subarray not having more than K distinct elements(Contest)
  • βœ…Maximum value of difference of a pair of elements and their Index(Contest)
  • βœ…Minimum adjacent difference in a circular array easy(Contest)
  • βœ…Minimum Element in Sorted and Rotated Array(Contest)
  • βœ…Minimum operation - II(Contest)
  • βœ…Missing two(Contest)
  • βœ…Mohit and array(Contest)
  • βœ…Most occurring elements(Contest)
  • βœ…Move Zeros(Contest)
  • βœ…Moving right (Contest)
  • βœ…Max Score in Quiz (Contest)
  • βœ…N integers: Easy (Contest)
  • βœ…Nth node from end of linked list(Contest)
  • βœ…Number of distinct numbers(Contest)
  • βœ…Odd Sum Array (Contest)
  • βœ…Optimal Goodies (Contest)
  • βœ…Orange or Chocolate Candy? (Contest)
  • βœ…Packing Rectangles (Contest)
  • βœ…Pair sum (Contest)
  • βœ…Passcode (Contest)
  • βœ…Permutation - 2 (Contest)
  • βœ…Polynomial equation(Contest)
  • βœ…Power function(Contest)
  • βœ…Power of Three(Contest)
  • βœ…Print Pattern (Contest)
  • βœ…Reduce to 1 (Contest)
  • βœ…Remove Duplicates Inplace(Contest)
  • βœ…Repeating numbers (Contest)
  • βœ…Replace element(Contest)
  • βœ…Ropes (Contest)
  • βœ…Row Index Identification (Contest)
  • βœ…Row with maximum 1's(Contest)
  • βœ…Sara and Monsters (Contest)
  • βœ…Science Camp (contest)
  • βœ…Score bar(Contest)
  • βœ…Search in rotated sorted array(Contest)
  • βœ…Searching an element in a sorted array(Contest)
  • βœ…Separating Negative and Positive numbers(Contest)
  • ❌Sequence Formation (Contest)
  • ❌Setwet's Fish Pond(Contest)
  • βœ…Shopping (Contest)
  • βœ…Simple Circle (Simple Contest)
  • βœ…Simple Pairs(Contest)
  • βœ…Simple Transpose (Contest)
  • βœ…Skit Video (Contest)
  • βœ…Smaller elements (Contest)
  • βœ…Sort it (Contest)
  • βœ…Special digit sum (Contest)
  • βœ…Spiral rotation(Contest)
  • βœ…Squiggly brackets (Contest)
  • βœ…Strange element (Easy-Version)
  • βœ…Subarray with given sum(Contest)
  • βœ…Sum of largest elements(Contest)
  • βœ…Sum Up(Contest)
  • βœ…Swapping Matrix (Contest)
  • βœ…Sweet Bunty (Contest)
  • βœ…Teacher(Contest)
  • βœ…The EndGame : Concatenated Words(Contest)
  • βœ…The high median paradigm (Contest)
  • βœ…Tower of Hanoi(Contest)
  • βœ…Transpose of a matrix(Contest)
  • βœ…Triangular matrix (Contest)
  • βœ…Two Sum Maximization(Contest)
  • βœ…Ultron : Vibranium Quest(Contest)
  • βœ…Wakandan Point in Unsorted Array(Contest)
  • βœ…Yet again Partition sort problem (Contest)
  • βœ…Yet Another Array Rearrangement Problem (Contest)
  • βœ…Zero Padding(Contest)
  • βœ…First & Last (Contest)
  • ❌Fast Search (Contest)
Powered by GitBook
On this page

Guardians of Galaxy(Contest)

Guardians of Galaxy easy Time Limit: 2 sec Memory Limit: 128000 kB

PreviousGrid Magic (Contest)NextHappy Balloons (Contest)

Last updated 2 years ago

Problem Statement :

After saving the planet of Xander in 2014 from Ronan, the guardians of the galaxy decided to play a game on it. Between the vast furious oceans, they discover a row of buildings. The buildings are of different heights arranged at each index along a number line. Gamora starts at building 0 and a height of 0. Groot gets the task to determine the minimum thrust that Gamora needs at the start of the game so that she can jump to the top of each building without her thrust going below zero. Write a code to help Groot with his task. The units of height relate directly to units of thrust. Gamora’s thrust level is calculated as follows: β€’ If gamora's thrust is less than the height of the building, her new thrust = gamora's thrust – (height – gamora's thrust) β€’ If gamora's thrust is greater than equal to the height of the building, her new thrust = gamora's thrust + (gamora's thrust - height) Input The first line contains an integer n, the number of buildings. The second line n space-separated integers, arr[1], arr[2]…arr[n], the heights of the building.

Constraints:- 1 ≀ n ≀ 105 1 ≀ arr[i] ≀ 105 Output The output contains a single integer denoting the minimum thrust Gamora needs at the start of the game. Example Sample Input:- 5 3 4 3 2 4

Sample Output:- 4

Explanation:- If we take 3 then:- at index 1:- 3 + 3-3 = 3 at index 2:- 3 - (4-3) = 2 at index 3:- 2 - (3-2) = 1 at index 4:- 1 - (2-1) = 0

Sample Input:- 3 4 4 4

Sample Output:- 4

link:

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        // Your code here
        Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int[] arr = new int[n];
       for(int i=0; i<n; i++){
           arr[i] = sc.nextInt();
       }
       long low =0;
       long high= Integer.MAX_VALUE;
       long ans =0;
       while(low <= high){
           long mid = low+ (high -low) /2;
           long newThrust = mid;
           newThrust = gamoThrust(arr, newThrust);
           if(newThrust >= 0){
               ans = mid;
               high = mid -1;
           }else{
               low = mid +1;
           }
       }
    
    System.out.println(ans);
}
private static long gamoThrust(int[] arr, long newThrust){
    for(int i =0; i< arr.length; i++){
        newThrust = newThrust*2 - arr[i];
        if(newThrust >= Integer.MAX_VALUE){
            return 1;
        }
        if(newThrust <0){
            return -1;
        }
    }
    return newThrust;
}
}
```
//method 02
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static boolean passAll(int x, int b[]){
        int energy= x;
        int n=b.length;
        for(int i=0; i<n; i++){
            energy+=energy-b[i];
            if(energy>=100000)
            return true;
            if(energy<0){
                return false;
            }
        }
        return true;
    }
    public static void main (String[] args) {
        // Your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
       int r=0;
       int b[]= new int[n];
       for(int i=0; i<n; i++){
           b[i]=sc.nextInt();
           if(b[i]>r){
               r=b[i];
           }
       }
       int l=0, res=0;
       while(l<=r){
           int m=l+(r-l)/2;
           if(passAll(m,b)){
               r=m-1;
               res=m;
           }else{
               l=m+1;
           }
       }
       System.out.println(res);
    }
}
```
βœ…
https://my.newtonschool.co/playground/code/7uaixk0xfdzq/