Skip to content
🤔prompts chat🧠
🔍
question:Consider an application in which the security system uses a password-based mechanism to allow access. The password system is designed such that it only allows strong passwords. A strong password is defined as: - At least 8 characters long. - Contains at least one lowercase letter. - Contains at least one uppercase letter. - Contains at least one digit. - Contains at least one special character from the set: !@#%^&*()-+ Write a function that takes a string input and returns `True` if the password is strong based on the aforementioned criteria, and `False` otherwise. Function Signature: ```python def is_strong_password(password: str) -> bool: ``` Input - A string `password` (1≤|password|≤100), representing the password to be checked. Output - A boolean value `True` if the password meets all the criteria for being strong, otherwise `False`. Examples Input `Password@123` Output `True` Input `weakpass` Output `False` Input `Str0ng!` Output `False`

answer:def is_strong_password(password: str) -> bool: Check if a given password is strong based on the following conditions: - At least 8 characters long. - Contains at least one lowercase letter. - Contains at least one uppercase letter. - Contains at least one digit. - Contains at least one special character (!@#%^&*()-+). :param password: str, password to check :return: bool, True if the password is strong, False otherwise if len(password) < 8: return False has_lower = any(char.islower() for char in password) has_upper = any(char.isupper() for char in password) has_digit = any(char.isdigit() for char in password) has_special = any(char in "!@#%^&*()-+" for char in password) return has_lower and has_upper and has_digit and has_special

question:Given a string of text, your task is to find the longest subsequence where each character appears exactly once and the characters are in alphabetical order. The characters in the subsequence do not need to be contiguous in the original string but must appear in the same relative order. # Input The input consists of a single string of length n (1 ≤ n ≤ 100,000). # Output Output the longest subsequence in alphabetical order where each character appears exactly once. # Examples Example 1 # Input: ``` abracadabra ``` # Output: ``` abr ``` Example 2 # Input: ``` abcxyzacb ``` # Output: ``` abcxyz ``` Example 3 # Input: ``` zxvutsrqponmlkjihgfedcba ``` # Output: ``` z ```

answer:def longest_alphabetic_subsequence(s): Finds the longest subsequence in which each character appears exactly once and is in alphabetical order. result = [] last_char = '' for char in s: if char > last_char: result.append(char) last_char = char return ''.join(result)

question:You are working at a software company where you need to maintain a database of employees and their monthly performance scores. Each employee is evaluated every month on a scale from 0 to 100. The database contains records for multiple employees over multiple months. Your task is to write a program that inputs a series of employee performance scores and calculates the following statistics for each employee: 1. The average performance score over all recorded months. 2. The highest performance score achieved. 3. The lowest performance score achieved. Input The input consists of multiple datasets. Each dataset represents the performance scores of one employee over several months. Each dataset starts with an integer `n` (1 ≤ n ≤ 12), representing the number of months for which performance scores are provided, followed by a sequence of `n` integers (0 ≤ score ≤ 100) representing the performance scores for each month. The end of input is indicated by a single line containing the integer zero `0`. Output For each dataset, output the average performance score (rounded to two decimal places), the highest performance score, and the lowest performance score for the employee, separated by spaces. Example Input 4 95 85 90 100 3 70 60 80 2 100 85 0 Output 92.50 100 85 70.00 80 60 92.50 100 85

answer:def employee_performance_statistics(input_data): Given a list of datasets where each dataset represents the performance scores of an employee over several months, this function calculates the average performance score, the highest performance score, and the lowest performance score for each dataset. Parameters: input_data (list of lists): List of datasets where each dataset is a list containing the number of months followed by the performance scores. Returns: list of tuples: Each tuple contains the average performance score, highest performance score, and lowest performance score for an employee in the corresponding dataset. results = [] for data in input_data: if data[0] == 0: break n = data[0] scores = data[1:n+1] average_score = round(sum(scores) / n, 2) highest_score = max(scores) lowest_score = min(scores) results.append((average_score, highest_score, lowest_score)) return results # Sample Input and Output to test the function input_data = [ [4, 95, 85, 90, 100], [3, 70, 60, 80], [2, 100, 85], [0] ] print(employee_performance_statistics(input_data)) # Expected Output: [(92.5, 100, 85), (70.0, 80, 60), (92.5, 100, 85)]

question:A city is divided into a grid of n rows and m columns. Each cell in the grid can either be land or water. Land cells are represented by '1' and water cells are represented by '0'. Two cells are adjacent if they share a side (north, south, east, or west). An island is a maximal group of land cells that are connected. You are given a grid representation of a city. Your task is to find the number of distinct islands in the city. Input: The first input line contains two integers n and m (1 ≤ n, m ≤ 1000) representing the number of rows and columns in the grid. The next n lines each contain m characters ('0' or '1'), representing the grid. Output: Print a single integer representing the number of distinct islands. Example Input: 4 5 11000 11000 00100 00011 Output: 3 Input: 3 3 110 010 011 Output: 1

answer:def num_islands(grid): if not grid or not grid[0]: return 0 n, m = len(grid), len(grid[0]) visited = [[False] * m for _ in range(n)] def dfs(x, y): if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == '0' or visited[x][y]: return visited[x][y] = True dfs(x + 1, y) dfs(x - 1, y) dfs(x, y + 1) dfs(x, y - 1) island_count = 0 for i in range(n): for j in range(m): if grid[i][j] == '1' and not visited[i][j]: dfs(i, j) island_count += 1 return island_count

Released under the chat License.

has loaded