Skip to main content

Command Palette

Search for a command to run...

Find if Digit Game Can Be Won

Published
1 min read
Find if Digit Game Can Be Won
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 an array of positive integers nums.

Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.

Return true if Alice can win this game, otherwise, return false.

LeetCode Problem - 3232

class Solution {
    public boolean canAliceWin(int[] nums) {

        // Initialize variables to keep track of sums of single and double-digit numbers
        int sumSingleDigit = 0;
        int doubleDigit = 0;

        // Iterate through the array of numbers
        for(int e : nums) {
            // If the number is a single-digit number (less than 10), add it to sumSingleDigit
            if(e < 10) sumSingleDigit += e;
            // If the number is a double-digit number (10 or greater), add it to doubleDigit
            else doubleDigit += e;
        }

        // Compare the sums of single and double-digit numbers
        // If they are not equal, Alice can win, so return true
        if(sumSingleDigit != doubleDigit) return true;

        // If the sums are equal, Alice cannot win, so return false
        return false;
    }
}

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.