Picking Numbers 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 Picking Numbers 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 ProblemPicking Numbers – Hacker Rank Solution

Picking Numbers – Hacker Rank Solution


Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to .


image 70

Function Description

Complete the pickingNumbers function in the editor below.

pickingNumbers has the following parameter(s):

  • int a[n]: an array of integers


  • int: the length of the longest subarray that meets the criterion

Input Format

The first line contains a single integer n, the size of the array a.
The second line contains n space-separated integers, each an a[i].

image 71

Sample Input 0

4 6 5 3 3 1

Sample Output 0


Explanation 0

image 72

Sample Input 1

1 2 2 3 1 2

Sample Output 1


Explanation 1

image 73
Picking Numbers – Hacker Rank Solution
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

 * @author Techno-RJ
public class PickingNumbers {

	public static int pickingNumbers(List<Integer> a) {
		int frequency[] = new int[101];
		int result = Integer.MIN_VALUE;

		for (int i = 0; i < a.size(); i++) {
			int index=a.get(i);
			frequency[index]++; //frequency[index]=frequency[index]+1

		for (int i = 1; i <= 100; i++) {
			result = Math.max(result, frequency[i] + frequency[i - 1]);
		return result;


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		while (n-- > 0) {

		int result = pickingNumbers(list);


168 thoughts on “Picking Numbers in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. To presume from actual rumour, follow these tips:

    Look representing credible sources: https://drsophie.co.uk/wp-content/pages/when-repeated-1968-name-in-the-news-crossword.html. It’s eminent to safeguard that the report origin you are reading is worthy and unbiased. Some examples of reputable sources subsume BBC, Reuters, and The Fashionable York Times. Announce multiple sources to pick up a well-rounded sentiment of a discriminating statement event. This can better you carp a more over paint and keep bias. Be aware of the position the article is coming from, as flush with respected hearsay sources can contain bias. Fact-check the gen with another commencement if a news article seems too lurid or unbelievable. Many times make unshakeable you are reading a advised article, as tidings can substitute quickly.

    Nearby following these tips, you can become a more in the know news reader and better know the cosmos here you.

  2. In-Game Achievements Ready to play for real at JV Spin? Sebelum anda bermain lebih jauh lagi, penting sekali bagi kalian untuk mengerti cara untuk mudah mendapatkan kemenangan saat bermain di situs judi slot online ini. Banyak sekali pemain di situs slot gacor DEWASLOTO yang sudah sering mendapatkan jackpot kemenangan terbesar hingga ratusan juta rupiah. Terlepas dari kemenangan mereka, mereka sudah menganalisa terlebih dahulu bagaimana cara memenangkan permainan slot di situs slot online ini. Berikut ini kami akan memberikan anda tips dan trick bermain di situs slot gacor jackpot terbesar DEWASLOTO: Tool Upgrades COPYRIGHT © 2015 – 2023. All rights reserved to Pragmatic Play – Any and all content included on this website or incorporated by reference is protected by international copyright laws.
    nah, untuk dapat melakukan deposit slot OVO kami akan memberikan sedikit tips atau cara deposit slot via OVO ke akun game slot online. Berikut langkah-langkah yang perlu diikuti; Sebelum anda bermain lebih jauh lagi di situs judi slot online ASIASLOT777. Kami akan memberikan anda beberapa macam informasi tentang game slot online yang kami sediakan. Kami akan memberikan informasi mengenai bocoran game slot online gacor hari ini:  Slot Real Time Gaming (Slot RTG) siap mengajak anda memasuki keseruan taruhan dimana kesempatan emas menang maxwin senilai puluhan ribu kali bet. Situs slot gacor satu ini telah beroperasi sejak 1998. Dalam perkembangannya Real Time Gaming pertama kali berdiri di Atlanta tahun 1998. Lalu kemudian mereka memindahkan kantor pusat ke Costa Rica di tahun 2008. Pengalaman panjang RTG merancang permainan jud sloti online telah cukup untuk menjamin bahwa daftar slot gacor RTG sangat recomended bagi anda para pecinta slot gacor. Beberapa slot RTP paling gacor yaitu slot T-Rex, slot Pay Dirt, dan slot Triple Twister.

  3. This year will be one to remember for Ethereum, in 2031 we expect that ETH will reach a new ATH of $16,039.56, the new minimum price of Ethereum could be $15,057.54. The worst case scenario is that ETH ends 2031 at $15,548.55. With the continued growth of capital in the crypto market, Ethereum could reach a maximum price of $7,856.11 in 2026 with an average price of $7,365.10. If a sell-off occurs, the minimum price expected in our prediction sits at $6,874.10. Ethereum currently uses a proof-of-work consensus mechanism. This means that anyone who wants to add new blocks to the chain must solve a difficult puzzle that requires a lot of computing power. Solving the puzzle “proves” that you have done the “work” by using computational resources. Doing this is known as mining. Mining is typically brute force trial and error, but successfully adding a block is rewarded in ETH.
    VVS got listed on Crypto on Nov. 23. After the listing, the coin saw a surge in its price and the volume traded. Crypto is a trading platform that rivals Coinbase and Binance with more than 10 million users. Crypto is trying to improve its visibility through ad campaigns featuring Hollywood actor Matt Damon and many other sports and celebrity partnerships. CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage. 79.59% of retail investor accounts lose money when trading CFDs. You should consider whether you understand how CFDs work and whether you can afford to take the high risk of losing your money The VVS Finance team makes the current governance decisions in consultation with the community feedback; however, to fully decentralize the protocol, VVS Finance intends to hand the project over to VVS token holders gradually.


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