Skip to main content

Command Palette

Search for a command to run...

The Two Sneaky Numbers of Digitville

Published
2 min read
The Two Sneaky Numbers of Digitville
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.

In the town of Digitville, there was a list of numbers called nums containing integers from 0 to n - 1. Each number was supposed to appear exactly once in the list, however, two mischievous numbers sneaked in an additional time, making the list longer than usual.

As the town detective, your task is to find these two sneaky numbers. Return an array of size two containing the two numbers (in any order), so peace can return to Digitville.

LeetCode Problem - 3289

class Solution {
    public int[] getSneakyNumbers(int[] nums) {
        // Create a list to keep track of unique numbers
        List<Integer> list = new ArrayList<>();
        // Initialize an array to store the sneaky numbers (duplicates)
        int[] answer = new int[2];
        int idx = 0; // Index to track the position in the answer array

        // Loop through each element in the input array
        for (int e : nums) {
            // Check if the number is not already in the list
            if (!list.contains(e)) {
                // If it's unique, add it to the list
                list.add(e);
            } else {
                // If it's a duplicate, store it in the answer array
                answer[idx] = e;
                idx++; // Move to the next index in the answer array

                // If we have found two sneaky numbers, return the answer
                if (idx == 2) return answer;
            }
        }
        // If less than two sneaky numbers are found, return null
        return null;
    }
}

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.