Problem Statement:
Uber's security team is working on password security for the employees. For setting up a password, the guidelines mentioned by them are:
You are given a password string s as the input. You need to tell us the minimum number of iterations (steps) you would need to make it an UBER strong password. If you think your password is already passing all the checks, then return 0.
In one step, you can:
Constraints:
Example:
Input:
"abc"
Output:
3
Output Explanation:
The minimum password length required is 6, so you need to add 3 characters to your password. Here, you would need to add one uppercase, one digit, and one random character of your choice.
Problem Statement:
In the kingdom of Eldoria, a legendary royal vault holds priceless jewels, secured behind multiple chambers. Each chamber is protected by complex security systems, and each chamber has a different security level. A group of elite thieves plans to steal the jewels, but they are limited by the time they have to disable the security systems. The jewel value and time to disable the security systems increase with the security level of each chamber.
Your task is to help the thieves maximize the total jewel value they can steal within a given time limit, where each chamber can only be robbed once.
The jewel value and time to disable the security system for each chamber depend on the security level. Specifically:
Input Format:
Output:
Return the maximum total jewel value the thieves can steal within the total time limit.
Problem 1 Uber Security Team (Strong Password Checker) Solution
Topics Involved
String Manipulation
Overview
Approach
1. Counting Missing Types First, we scan the string to check if it contains at least one lowercase letter, one uppercase letter, and one digit. We count how many of these three categories are missing, storing it as
missingTypes(which will be between 0 and 3).2. Handling the Three Length Scenarios
Length < 6: We need to add characters. A single insertion can break a repeating sequence, add a missing type, and fix the length simultaneously. The answer is simply
max(6 - length, missingTypes).Length between 6 and 20: We only need replacements. A single replacement breaks a repeating sequence of 3. We calculate the total replacements needed for all repeating groups and return
max(replacements, missingTypes).Length > 20: We must delete characters. To minimize replacements later, we delete characters from repeating sequences. We prioritize sequences where the length modulo 3 is 0, then 1, and finally 2, as this yields the most efficient reduction in required replacements.
Code Implementation
Time Complexity
Time: O(N) - We iterate through the password string a constant number of times to count character types and repeating sequences.
Space: O(N) - To store the lengths of the repeating sequences for processing deletions.
Problem2
Kingdom of Eldoria (Royal Vault Heist) Solution
Topics-:
Dynamic Programming (1D Array)
0-1 Knapsack Optimization
Overview
Approach
1. Preprocessing the Inputs
The raw inputs given for each chamber do not directly represent the final cost and reward. We must iterate through the given array and calculate the
effectiveValue(Base Jewel Value $\times$ Security Level) and theactualTime(Time to Disable $\times$ Security Level) for every single chamber.2. Dynamic Programming (0-1 Knapsack)
We create a DP array of size
t + 1, wheredp[j]represents the maximum jewel value we can steal exactly injunits of time. For each chamber, we loop backward through our DP array from the maximum timetdown to the chamber'sactualTime. At each step, we decide whether it is more profitable to skip the chamber or to rob it by checkingmax(dp[j], dp[j - actualTime] + effectiveValue).Code Implementation
Time Complexity
Time: O(N *T) - Where N is the number of chambers and T is the total time available. We loop through time T for every single chamber.
Space: O(T) - We only need a single 1D array of size T + 1 to store the states, heavily optimizing our memory footprint compared to a 2D matrix.