Marc’s Cakewalk in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Marc’s Cakewalk in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To Algorithm

The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results. 

Advantages of Algorithms:

  • It is easy to understand.
  • Algorithm is a step-wise representation of a solution to a given problem.
  • In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.

Link for the ProblemMarc’s Cakewalk – Hacker Rank Solution

Marc's Cakewalk – Hacker Rank Solution

Problem:

Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie count, and Marc can walk a distance to expend those calories. If Marc has eaten  cupcakes so far, after eating a cupcake with  calories he must walk at least  miles to maintain his weight.

Example

image 101

Function Description

Complete the marcsCakewalk function in the editor below.

marcsCakewalk has the following parameter(s):

  • int calorie[n]: the calorie counts for each cupcake

Returns

  • long: the minimum miles necessary

Input Format

The first line contains an integer , the number of cupcakes in .
The second line contains  space-separated integers, .

Constraints

image 103

Sample Input 0

3
1 3 2

Sample Output 0

11

Explanation 0

Let’s say the number of miles Marc must walk to maintain his weight is . He can minimize  by eating the  cupcakes in the following order:

  1. Eat the cupcake with  calories, so .
  2. Eat the cupcake with  calories, so .
  3. Eat the cupcake with  calories, so .

We then print the final value of , which is , as our answer.

Sample Input 1

4
7 4 9 6

Sample Output 1

79

Explanation 1

image 102
Marc's Cakewalk – Hacker Rank Solution
import java.util.Scanner;

/**
 * @author Techno-RJ
 *
 */
public class MarcsCakewalk {
	public static int[] sort(int a[]) {

		for (int i = 1; i < a.length; i++) {
			for (int j = i; j > 0; j--) {
				if (a[j] < a[j - 1]) {
					int temp = a[j - 1];
					a[j - 1] = a[j];
					a[j] = temp;
				} else
					break;
			}
		}
		return a;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] calories = new int[n];
		for (int calories_i = 0; calories_i < n; calories_i++) {
			calories[calories_i] = in.nextInt();
		}
		int sortedArray[] = sort(calories);
		int j = 0;
		long sum = 0;
		for (int i = sortedArray.length - 1; i >= 0; i--) {
			sum = (sum + sortedArray[i] * (long) Math.pow(2, j++));
		}
		System.out.println(sum);
		in.close();
	}
}

33 thoughts on “Marc’s Cakewalk in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. Jaime “PokerStaples” Staples, Parker “TonkaaaaP” Talbot, Doug “WCGRider” Polk, Lex “RasZi” Veldhuis and Randy “Nanonoko” Lew are just a few of the other poker stars who have embraced streaming live on Twitch and gathered massive followings. However, Twitch is not just for individual players, as major online poker sites like partypoker, Unibet Poker and 888poker have also taken to Twitch to stream a number of successful events via the platform. The Poker Forge members get full access to new strategies and courses as they are released from Smart Poker Study. About Pokertube About Pokertube Become a poker pro by learning the study principles and techniques that will lead to a successful and fun poker journey. In the poker section of Twitch, you’ll find streamers hosting a mix of old syndicated poker reruns like High Stakes Poker and Poker After Dark, big online tournaments with pro commentary, and individual streamers showing their current games.
    http://www.popsotong.com/gb/bbs/board.php?bo_table=free&wr_id=28359
    As for the other games, you can find a total of 300+ casino games here. This includes poker games, blackjack, as well as 10+ live casino games. Free Slots are considered one of the best types of free casino games online and are very popular in today’s gambling industry. Their prevalence is because free online slot machines allow gamblers to play their favorite games without downloading or registering. This super convenient feature gives you access to the most exciting and exciting video slots no download, where you can play for free. HollywoodCasino has all your favorite free slots online including 88 Fortunes, Lady Robin Hood, and Super Jackpot party, along with special promotions each month! The femme fatale characters from this Monstrous game are a sight for sore eyes! Watch out for exploding wilds that will give you the chills! Sink your teeth into the Monsterpedia slot series card collection for scary casino games fun!

    Reply

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker🙏.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock