Park 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Question1:

Problem statementThe new bank, "YoursPay", has a list of N customers' bank account balances. The
list consists of both positive and negativebalances. The positive balance signies the current year's
customers and the negative balance signies last year's customers. The bankhas decided to offer
shortlisted customers credit scores to their credit cards. The credit score will be the sum of the two
balances fromthe list with the smallest product when multiplied. If the credit score is positive then
the credit will be provided to the current year'scustomer, otherwise, it will go to the last year's
customer
Problem Statement Analysis:

The problem involves processing a list of bank account balances for both current and last year's
customers. The task is to determine the credit scores for each customer based on the sum of the two
balances with the smallest product when multiplied. The credit score is used to decide whether to
provide credit to the current year's customer or the last year's customer.

Key Components of the Problem:

1. List of Balances:
 The input consists of a list of N customers' bank account balances, with positive balances
representing current year customers and negative balances representing last year's
customers.
2. Credit Score Calculation:
 The credit score is determined by finding the two balances with the smallest product when
multiplied. The sum of these two balances becomes the credit score for that customer.
3. Decision Rule:
 If the credit score is positive, credit is provided to the current year's customer. Otherwise,
credit goes to the last year's customer.

Possible Steps to Solve the Problem:

1. Input Processing:
 Read and process the list of N customers' bank account balances.
2. Balances Comparison:
 For each customer, identify pairs of balances and calculate their product. Keep track of the
pair with the smallest product.
3. Credit Score Calculation:
 Calculate the credit score as the sum of the balances in the identified pair.
4. Decision Making:
 Based on the credit score, determine whether to provide credit to the current year's customer
or the last year's customer.
5. Output:
 Display or output the credit scores and the corresponding decisions for each customer.

Example:
Suppose the list of balances is [5, -3, 8, -2]. The pairs and their products are:

 (5, -3) → Product: -15


 (5, 8) → Product: 40
 (5, -2) → Product: -10
 (-3, 8) → Product: -24
 (-3, -2) → Product: 6
 (8, -2) → Product: -16

In this example, the pair (5, -2) has the smallest product (-10), so the credit score for the first
customer is 5 + (-2) = 3. Since the credit score is positive, credit will be provided to the current year's
customer.

Note:

 Additional details about the problem, such as the desired output format and any constraints, would
be essential for a more precise solution

Python code:

def calculate_credit_scores(balances):

# Initialize variables to keep track of the best pair and product

best_pair = (balances[0], balances[1])

best_product = balances[0] * balances[1]

# Iterate through pairs and find the one with the smallest product

for i in range(len(balances) - 1):

for j in range(i + 1, len(balances)):

product = balances[i] * balances[j]

if product < best_product:

best_product = product

best_pair = (balances[i], balances[j])


# Calculate credit score as the sum of the best pair

credit_score = sum(best_pair)

# Determine the decision based on the credit score

decision = "Credit provided to current year's customer" if credit_score > 0 else "Credit provided to last
year's customer"

return credit_score, decision

# Function to take user input for balances

def input_balances():

try:

# Input the number of customers

num_customers = int(input("Enter the number of customers: "))

# Input balances for each customer

balances_list = []

for i in range(num_customers):

balance = int(input(f"Enter balance for customer {i + 1}: "))

balances_list.append(balance)

return balances_list

Question No: 2

Single File Programming Question

Problem statement:
The MNC 'Softcomp' had a security breach recently and company offcials have decided to change
the system password. The system password is in string format tagged a-z or A-Z. To change the password
the ocials will simply convert the lowercase characters of theold password to uppercase, and uppercase
characters of the old password to lowercase.Write an algorithm to display the new password. If no such
password is possible display null

Certainly! Below is a simple algorithm in pseudocode to achieve the described password transformation:

Algorithm: ChangePassword

Input:

- oldPassword (string)

Output:

- newPassword (string)

1. Initialize an empty string newPassword.

2. For each character c in oldPassword:

a. If c is a lowercase letter, convert it to uppercase and append to newPassword.

b. If c is an uppercase letter, convert it to lowercase and append to newPassword.

c. If c is not a letter, append it to newPassword as it is.

3. If newPassword is different from oldPassword, set it as the new password.

Otherwise, set newPassword to null.

4. Display the new password or "null" if no change was made.


Example:

oldPassword = "SecuriTy123"

newPassword = ChangePassword(oldPassword)

Display newPassword

This algorithm iterates through each character of the old password, converts lowercase letters to
uppercase, and uppercase letters to lowercase. If the new password is different from the old password, it
is considered the updated password; otherwise, the new password is set to null.

Note: The actual implementation of this algorithm in a programming language (like Python, Java, etc.)
would involve specific functions for converting case and handling strings. If you have a preference for a
specific programming language, I can provide a code example in that language.

Python:

def change_password(old_password):

new_password = ""

for char in old_password:

if char.islower():

new_password += char.upper()

elif char.isupper():

new_password += char.lower()

else:

new_password += char

if new_password != old_password:

return new_password

else:

return None
# Example usage

old_password = input("Enter the old password: ")

new_password = change_password(old_password)

if new_password is not None:

print("New Password:", new_password)

else:

print("No change in password. The new password is null.")

This Python program defines a function change_password that iterates through each character of the old
password, converts lowercase letters to uppercase, and uppercase letters to lowercase. If the new
password is different from the old password, it is returned; otherwise, None is returned. The program then
takes user input for the old password, applies the function, and prints the new password or "No change in
password. The new password is null." based on the result.

You might also like