Skip to main content

Command Palette

Search for a command to run...

Defuse the Bomb

Published
2 min read
Defuse the Bomb
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 have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k.

To decrypt the code, you must replace every number. All the numbers are replaced simultaneously.

  • If k > 0, replace the i<sup>th</sup> number with the sum of the next k numbers.

  • If k < 0, replace the i<sup>th</sup> number with the sum of the previous k numbers.

  • If k == 0, replace the i<sup>th</sup> number with 0.

As code is circular, the next element of code[n-1] is code[0], and the previous element of code[0] is code[n-1].

Given the circular array code and an integer key k, return the decrypted code to defuse the bomb!

LeetCode Problem - 1652

class Solution {
    public int[][] transpose(int[][] matrix) {
        // Initialize a new matrix with dimensions swapped compared to the input matrix
        int[][] result = new int[matrix[0].length][matrix.length];

        int col = 0; // This variable keeps track of the column index in the result matrix

        // Outer loop iterates over the rows of the input matrix
        for (int i = 0; i < matrix.length; i++) {
            int row = 0; // This variable keeps track of the row index in the result matrix

            // Inner loop iterates over the columns of the input matrix
            for (int j = 0; j < matrix[0].length; j++) {
                int temp = matrix[i][j]; // Store the current element of the input matrix
                result[row][col] = temp; // Assign the current element to the transposed position in the result matrix
                row++; // Move to the next row in the result matrix
            }

            col++; // Move to the next column in the result matrix after processing one row of the input matrix
        }

        return result; // Return the transposed matrix
    }
}

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.