Skip to main content

Command Palette

Search for a command to run...

Ransom Note

Published
1 min read
Ransom Note
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.

Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.

Each letter in magazine can only be used once in ransomNote.

LeetCode Problem - 383

class Solution {
    // Method to check if ransomNote can be constructed from magazine
    public boolean canConstruct(String ransomNote, String magazine) {
        // Creating a map to store characters and their frequencies in magazine
        Map<Character, Integer> mp = new HashMap<>();
        // Counting frequencies of characters in magazine
        for(char c : magazine.toCharArray()){
            mp.put(c, mp.getOrDefault(c, 0) + 1);
        }

        // Checking if characters in ransomNote can be formed using characters in magazine
        for (char c : ransomNote.toCharArray()){
            // Decreasing frequency of current character in the map
            mp.put(c, mp.getOrDefault(c, 0) - 1);
            // If the frequency becomes negative or the character is not present, return false
            if (mp.get(c) < 0){
                return false;
            }
        }
        // If all characters in ransomNote can be formed using characters in magazine, return true
        return true;
    }
}

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.