Cats and a Mouse 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 Cats and a Mouse 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 ProblemCats and a Mouse – Hacker Rank Solution

Cats and a Mouse – Hacker Rank Solution

Problem:

Two cats and a mouse are at various positions on a line. You will be given their starting positions. Your task is to determine which cat will reach the mouse first, assuming the mouse does not move and the cats travel at equal speed. If the cats arrive at the same time, the mouse will be allowed to move and it will escape while they fight.

You are given  queries in the form of , , and  representing the respective positions for cats  and , and for mouse . Complete the function  to return the appropriate answer to each query, which will be printed on a new line.

  • If cat  catches the mouse first, print Cat A.
  • If cat  catches the mouse first, print Cat B.
  • If both cats reach the mouse at the same time, print Mouse C as the two cats fight and mouse escapes.

Example

The cats are at positions  (Cat A) and  (Cat B), and the mouse is at position . Cat B, at position  will arrive first since it is only  unit away while the other is  units away. Return ‘Cat B’.

Function Description

Complete the catAndMouse function in the editor below.

catAndMouse has the following parameter(s):

  • int x: Cat ‘s position
  • int y: Cat ‘s position
  • int z: Mouse ‘s position

Returns

  • string: Either ‘Cat A’, ‘Cat B’, or ‘Mouse C’

Input Format

The first line contains a single integer, , denoting the number of queries.
Each of the  subsequent lines contains three space-separated integers describing the respective values of  (cat ‘s location),  (cat ‘s location), and  (mouse ‘s location).

Constraints

Sample Input 0

2
1 2 3
1 3 2

Sample Output 0

Cat B
Mouse C

Explanation 0

Query 0: The positions of the cats and mouse are shown below: image

Cat  will catch the mouse first, so we print Cat B on a new line.

Query 1: In this query, cats  and  reach mouse  at the exact same time: image

Because the mouse escapes, we print Mouse C on a new line.

Cats and a Mouse – Hacker Rank Solution
import java.util.Scanner;

/**
 * @author Techno-RJ
 *
 */
public class CatsAndAMouse {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int q = in.nextInt();
		for (int a0 = 0; a0 < q; a0++) {
			int x = in.nextInt();
			int y = in.nextInt();
			int z = in.nextInt();
			int a = Math.abs(x - z);
			int b = Math.abs(y - z);
			if (a == b) {
				System.out.println("Mouse C");
			} else if (a > b) {
				System.out.println("Cat B");
			} else if (a < b) {
				System.out.println("Cat A");
			}

		}
		in.close();
	}
}

128 thoughts on “Cats and a Mouse in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. If you’d been swayed by Kim Kardashian to buy ethereum max tokens last year, your holdings would have lost 95% of their value by now. Brown’s former teammate, Tom Brady, lost millions when FTX collapsed. Brady has been sued over the implosion of FTX, but he faces no regulatory or criminal scrutiny. District Judge Michael Fitzgerald of California said in his ruling on Wednesday that the case raised “legitimate concerns” about the ability of celebrities to persuade fans to “buy snake oil with unprecedented ease and reach”. According to the SEC, T.I.’s sold FLiK tokens on his social-media accounts while encouraging his followers to invest in the ICO. T.I. distanced himself from Felton, who was indicted over the alleged fraud, as Felton allegedly used his investors’ cash to buy a Ferrari, a million-dollar home and diamond jewelry.
    http://www.homniz.co.kr/support//bbs/board.php?bo_table=free&wr_id=21127
    Recently Pi has introduced their most awaited product Pi Apps Platform in beta version(means initial user acceptance testing phase) full proof version is yet to launch officially. Many developers from including from Pi Community and other developer community were eagerly waiting for this 2nd Phase of Pi Network.  With the help of this “Pi Apps Platform” developers can start developing mobile or desktop application which will integrate “Pi” as primary currency for transactions or payments. Also, this “Pi Apps Platforms” soon support third party application to use their “Pi” currency as payment method. For example, you may be soon able to pay on Amazon(online) or local shops(offline) using Pi Currency. Meanwhile, Pi Network’s Android application has more than 50 million app installs, which is significantly higher than other crypto wallets. And, most installers appear to love the application since it has an outstanding 4.7-star rating. Pi also has millions of iOS users.

    Reply
  2. With havin so much written content do you ever run into any problems of plagorism or
    copyright infringement? My site has a lot of unique
    content I’ve either created myself or outsourced but it seems a lot
    of it is popping it up all over the web without my authorization. Do you know any solutions to help prevent content from being ripped off?
    I’d certainly appreciate it.

    Reply
  3. Understanding Roulette betting odds and how the payouts work is an important part of playing this online casino game in Canada. Knowing your win potential for each bet you place will influence your betting decisions and strategy when you play Roulette online with us at Spin Casino Canada. Let’s explore some Roulette bets you’ll come across while playing and your potential payouts from each. With money in your account, you’re ready to play real money mobile roulette. Navigate your phone or mobile device’s browser to the mobile version of your casino’s website and you’ll find all of their mobile games ready for play there. Find the roulette game and, once it loads, you can make all of the same bets you’d have available to you at a live casino. Do you have questions about playing online roulette? We’re answering all your most frequently asked questions about roulette play below.
    https://www.selfdoctorcafe.com/bbs/board.php?bo_table=free&wr_id=124234
    Another way of how no deposit bonuses find their way to your account is when you contact the customer support unit at your casino of choice. You have to contact the customer support and inquire into what bonuses there are and how to obtain them. This might be a slow process, but sometimes casinos want to keep a separate record of how many no deposit bonuses have been claimed. BetOnRed Casino Review Sign Up Bonus: 100% up to €150 + 250 Spins 2nd Deposit Bonus: 55% up to €150 3rd Deposit Bonus: 100% up to €150 Sign Up Bonus – South Africa: 100% up to R2,500 +… No deposit bonuses are a type of casino bonuses given to players without the need for them to deposit their own money into the casino. Casinos use them as a promotional tool to give new players an incentive to create an account and start playing. No deposit bonuses make it possible to essentially gamble for free, but their values are generally low.

    Reply
  4. Shiba Inu (SHIB), the ERC-20 meme coin token that powers the Shiba Inu web3 ecosystem, was last trading around $0.0000075, down more than 90% from its 2021 all-time highs in the $0.000088 area. The Shiba Inu blockchain ecosystem is powered by the primary token called SHIB, also known as the Shiba Inu coin, which is an Ethereum-based ERC-20 token. In addition to the trading incentive-bearing SHIB token, the Shiba Inu ecosystem consists of two more digital assets. Bone ShibaSwap (BONE) allows owners to participate in the decision-making process thanks to its governance capabilities, while Doge Killer (LEASH) acts as the network’s store of value due to its artificially capped token supply. >> Buy Shiba Inu (SHIB) quickly and securely with PayPal, credit card or bank transfer at eToro with low fees and deposit protection. Get started with SHIB now. Visit Website
    http://miltacoutdoor.com/bbs/board.php?bo_table=free&wr_id=50801
    The network, connected to some of the biggest names in crypto and finance, showed a plunge of about 90% for bitcoin to $5,402 on Monday. Other platforms showed the token trading around $43,000, down 8%. Attempting to take advantage of such confusion is a tactic employed by some bad actors looking to profit from unsuspecting consumers. The best way to avoid falling victim to a phony company or website is to do research on the company before you invest or send money. By early 2013, the leading cryptocurrency had recovered from a prolonged bearish episode and rose above $1,000, albeit only briefly. But with the infamous Mt Gox hack, China announcing its first ban on crypto and other situations, it took a further four years for the BTC price to return to above $1,000 again. Once that level was passed, however, bitcoin’s price continued to surge dramatically throughout 2017 until BTC peaked at its previous long-standing all-time high of $19,850.

    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