Skip to main content

Command Palette

Search for a command to run...

House Robber

Published
2 min read
House Robber
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 a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

LeetCode Problem - 198: Link | Click Here

class Solution {
    public int rob(int[] nums) {
        // Get the length of the input array
        int len = nums.length;

        // If the array is empty, no houses to rob, return 0
        if(len == 0) return 0;

        // Create an array to store the maximum amount robbed up to the ith house
        int dp[] = new int[len + 1];

        // Initialize the base cases for the first and second houses
        dp[0] = 0;          // No houses, no money
        dp[1] = nums[0];    // Only one house, rob it

        // Loop through the houses starting from the second one
        for(int i = 1; i < len; i++) {
            // Calculate the maximum amount that can be robbed at the current house
            // by either skipping the current house and taking the previous maximum,
            // or by robbing the current house and adding the maximum amount robbed
            // from two houses ago (to avoid robbing adjacent houses).
            dp[i + 1] = Math.max(dp[i], dp[i - 1] + nums[i]);
        }

        // Return the maximum amount that can be robbed from any of the houses
        return dp[dp.length - 1];
    }
}

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.