Time Conversion 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 Time Conversion 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 ProblemTime Conversion – Hacker Rank Solution

Time Conversion– Hacker Rank Solution


image 47
All input times are valid
Sample Input 0
Sample Output 0
Time Conversion – Hacker Rank Solution
public class TimeConversion {
	static String timeConversion(String s) {
		String[] str = s.split(":");
		int hour = Integer.parseInt(str[0]);

		String min = str[1];
		String secPeriod = str[2];
		String sec = str[2].substring(0, secPeriod.length() - 2);
		String period = str[2].substring(secPeriod.length() - 2, secPeriod.length());

		String newTimeINString = "";

		if ((0 <= hour && hour < 12) && (period.equalsIgnoreCase("AM"))) {
			newTimeINString = String.format("%02d", hour) + ":" + min + ":" + sec;
		} else if ((0 <= hour && hour < 12) && period.equalsIgnoreCase("PM")) {
			newTimeINString = (12 + hour) + ":" + min + ":" + sec;

		} else if ((hour == 12) && (period.equalsIgnoreCase("AM"))) {
			newTimeINString = "00" + ":" + min + ":" + sec;
		} else if ((hour == 12) && (period.equalsIgnoreCase("PM"))) {
			newTimeINString = hour + ":" + min + ":" + sec;
		return newTimeINString;


88 thoughts on “Time Conversion in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. When a player is dealt two cards of the same value (two fours, tens, etc.,) they have the options to split the two cards and play each hand individually, making another hands. A player must bet the same amount as their original wager on the split hand and say “split”. If a player’s next card is of equal value to the first pair, a player may split again. A player may also “double down” on the first two cards of each hand after a player split, except when splitting Aces. For those who could read between the lines, the censored news out of China was terrifying. But the president insisted there was nothing to worry about. Fortunately, we are still a nation of skeptics. Fortunately, there are those among us who study pandemics and are willing to look unflinchingly at worst-case scenarios. Michael Lewis’ taut and brilliant nonfiction thriller pits a band of medical visionaries against the wall of ignorance that was the official response of the Trump administration to the outbreak of COVID-19.
    New post, adam27944 replied to June 5th – Weekly Winners Following @GossipSlots on social media also comes with its own set of rewards. The casino had plenty of generous offers like free casino bets, free spins, special deposit bonuses and loads more for the members who follow them on Twitter. The casino tweets many of its latest and most exclusive promotions. This means that you should not only be looking at the promotions page on the casino’s site because you may end up missing out on a beneficial bonus deal. © 2023 Casino-Bonus.Club Created in 2013, Gossip Slots has become a household name in the US. Lots of players favour the reels of the casino because of the beautifully designed gaming lobby with all the necessary features boldly listed out waiting for the next interested player to click on it. The casino does not require any sort of download. Most of its features can be accessed via instant play on a mobile or pc. A support team is also available at the gaming lobby on a 24 hours basis while the huge list of games provided would keep you gaming all day.


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