Skip to main content

Command Palette

Search for a command to run...

Minimum Number Game

Published
1 min read
Minimum Number Game
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:

  • Every round, first Alice will remove the minimum element from nums, and then Bob does the same.

  • Now, first Bob will append the removed element in the array arr, and then Alice does the same.

  • The game continues until nums becomes empty.

Return the resulting array arr.

LeetCode Problem - 2974

import java.util.Arrays; // Import necessary library for Arrays

class Solution {
    public int[] numberGame(int[] nums) {
        int[] arr = new int[nums.length]; // Initialize a new array to store rearranged numbers
        Arrays.sort(nums); // Sort the input array in ascending order
        for(int i=0; i<nums.length-1; i+=2){ // Iterate through the sorted array by 2 steps
            arr[i] = nums[i+1]; // Place the next higher number at even index
            arr[i+1] = nums[i]; // Place the next lower number at odd index
        }
        return arr; // Return the rearranged array
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.