Tip 1: Practice as many questions as you can in DSA
Tip 2: Keep all your theoretical knowledge and concepts clear.
Tip 3: Participate in CodeChef, code-forces.
Tip 1: Keep your resume clean and free of false information.
Tip 2: Ensure that you include projects on your resume.
Inyftq Qualifier round
This is an optional round anyone can directly give the Hackwithinfy but I choose to give both since there are different packages for Inyftq and Hackwithinfy and Hackwithinfy has the highest package. I gave Inyftq for the practice since Hackwithinfy is considered as one of the toughest exam.
Inyftq Final round
This is an optional round anyone can directly give the Hackwithinfy but I choose to give both since there are different packages for Inyftq and Hackwithinfy and Hackwithinfy has the highest package. I gave Inyftq for practice since Hackwithinfy is considered as 1 of the toughest exams.



In a scenario where you are the manager of a bustling hotel, overseeing the comfort and satisfaction of numerous guests, each guest brings a unique aspect to consider: their happiness level (Ci) is directly tied to the timing of their service. The happiness of a guest is inversely proportional to the time they wait for service—guests become increasingly unhappy the longer they wait. This unhappiness is quantified as |Ci – x|, where Ci represents the guest's happiness level and x denotes the time they are served.
Imagine you have N guests to attend to, with each guest's happiness value and the urgency of their service varying. Your goal is clear: minimize the total unhappiness experienced by all guests. This involves strategizing the order in which guests are served to optimize their happiness levels.
However, there are constraints to consider in this endeavor:
- The number of guests N ranges from 1 to 10^3.
- Each guest's happiness value Ci falls between 1 and N.
Given this context, delve into how you would approach this challenge as the manager, considering the intricacies of guest satisfaction and efficient time management.
Here is a step-by-step solution for the problem described:
1. **Input**: Obtain the input values, including the number of guests (N) and their happiness values (Ci).
2. **Sort the happiness values**: Arrange the happiness values in ascending order. This step helps minimize the total unhappiness.
3. **Initialize variables**: Set up variables such as total unhappiness (totalUnhappiness) and current time (currentTime) to keep track of the serving process.
4. **Iterate through guests**:
- Start a loop to iterate through each guest, starting from the first (smallest happiness value).
- For each guest:
- Calculate their unhappiness as |Ci - currentTime|.
- Add this unhappiness to the totalUnhappiness.
- Increment currentTime by 1 unit as each guest takes exactly one unit of time to be served.
5. **Output**: Once all guests are served, output the totalUnhappiness, which represents the minimum total unhappiness achieved by serving all guests in an optimized order.
Let's illustrate this with an example:
Input: 4 2 2 3 3
1. Sort the happiness values: 2 2 3 3
2. Initialize totalUnhappiness = 0 and currentTime = 0
3. Iterate through guests:
- Guest 1 (happiness 2): |2 - 0| = 2, totalUnhappiness = 2, currentTime = 1
- Guest 2 (happiness 2): |2 - 1| = 1, totalUnhappiness = 2 + 1 = 3, currentTime = 2
- Guest 3 (happiness 3): |3 - 2| = 1, totalUnhappiness = 3 + 1 = 4, currentTime = 3
- Guest 4 (happiness 3): |3 - 3| = 0, totalUnhappiness = 4 + 0 = 4, currentTime = 4
4. Output: Total unhappiness = 4
This step-wise solution ensures an optimized order of serving guests to minimize total unhappiness.



You are given an integer N representing the size of a chessboard, and the positions of M queens on this chessboard. Find the number of pairs of queens that are in an attacking position.
Input Format:
- The first line contains an integer, N, representing the size of the chessboard.
- The second line contains an integer, M, denoting the number of queens.
- Each of the next M lines contains two space-separated integers, representing the row and column coordinates of each queen.
Output Format:
- Print the number of pairs of queens that are in an attacking position. Since the answer can be large, return it modulo 10^9 + 7.
Constraints
- 1 <= N <= 10^6
- 1 <= M <= 10^5
- 1 <= Ai, Bi <= N, where Ai represents the row coordinate and Bi represents the column coordinate of the ith queen.



Given two strings A and B, the task is to convert A to B if possible. The only operation allowed is to put any character from A and insert it at the front. Find if it’s possible to convert the string. If yes, then output the minimum no. of operations required for transformation.
We declare a HashMap to store the frequency map.
We store the character of string 1 in the map and then while traversing string 2, we erase the characters if the map is empty at the end that means the characters in both strings are the same and we can continue, or else we return -1.
We make a variable res and point two pointers i and j to the last of both strings and start traversing from back.
As soon as see an ith character that doesn’t match with the jth character, we start increasing res by 1 until again both the characters are the same.
At last, we return the res.



You are given a tree with N nodes represented by an array P, where each element P[i] denotes the parent node of node i. Additionally, each node i has a value given by the array A. The XOR value of an element is defined as the XOR of all the elements in its subtree, including itself.
Write a function to find the sum of XOR values of all nodes in the tree modulo 10^9+7.
Here's a stepwise solution for finding the sum of the XOR values of all nodes in a tree:
1. Create Tree Structure:
- Initialize a list of lists or a dictionary to represent the tree structure based on the parent-child relationships defined in array P.
3. Calculate XOR Values Recursively:
- Implement a recursive function to calculate the XOR value for each node and its subtree.
- Start with the root node (node 0) and recursively process each node:
- For each node, calculate its XOR value by XORing its value (A[i]) with the XOR values of its children.
- Recursively call the function for each child node to calculate their XOR values.
4. Sum XOR Values:
- Traverse the tree and sum up the XOR values of all nodes to get the total sum of XOR values in the tree.
5. Modulo Operation:
- After computing the sum of XOR values, perform a modulo operation with 10^9+7 to ensure the result stays within the specified range.
6. Return Result:
- Return the final sum of XOR values modulo 10^9+7 as the result.



Problem Statement:
Given an array of numbers [1, 2, 3, 4, 5, 6], find the sum of elements with specific indices within a given range.
Write a function to calculate the sum of elements in the array from index i to index j (inclusive), where i and j are specified as input.
Input Format:
The input consists of the following:
• An array of integers representing the elements: [1, 2, 3, 4, 5, 6]
• Two integers i and j, representing the start and end indices of the range.
Output Format:
Print the sum of elements in the array from index i to index j (inclusive).
Example:
Input:
Array: [1, 2, 3, 4, 5, 6]
Start Index: 1
End Index: 4
Output:
Sum: 14
Explanation:
In the given array [1, 2, 3, 4, 5, 6], the elements from index 1 to index 4 are [2, 3, 4, 5]. The sum of these elements is 2 + 3 + 4 + 5 = 14.
Code Snippet:
def calculateSumInRange(arr, start, end):
if start < 0 or end >= len(arr) or start > end:
return "Invalid range"
return sum(arr[start:end+1])
if __name__ == "__main__":
arr = [1, 2, 3, 4, 5, 6]
start = 1
end = 4
result = calculateSumInRange(arr, start, end)
print("Sum:", result)
This code calculates the sum of elements in the array within the specified range [start, end] and handles invalid ranges by returning an appropriate message. Adjust the input array and range values based on the actual problem requirements.



You are given an array of integers and a target sum. Write a function to find two numbers in the array that add up to the target sum. If such a pair exists, return their indices. If no pair is found, return “No solution”.
Input Format:
• An array of integers: [1, 5, 3, 7, 9]
• Target sum: 10
Output Format:
• If a pair is found: Indices of the two numbers that add up to the target sum.
• If no pair is found: “No solution”.
Example:
Input:
Array: [1, 5, 3, 7, 9]
Target Sum: 10
Output:
Indices: [1, 3] # Numbers at indices 1 and 3 (5 and 7) add up to 10.
Here are the steps to solve the Two Sum problem efficiently:
1. **Input Preparation**:
- Given an array of integers `nums` and a target sum `target`.
2. **Create a HashMap**:
- Initialize an empty HashMap to store the indices of elements.
3. **Iterate Through Array**:
- Iterate through each element in the array `nums` with index `i`.
4. **Check Complement**:
- Calculate the complement as `complement = target - nums[i]`.
- Check if the complement exists in the HashMap:
- If yes, return the indices `[hashMap[complement], i]`.
- If not, add the current element and its index to the HashMap.
5. **Return "No Solution"**:
- If the loop completes without finding a valid pair, return "No solution".
6. **Code Implementation** (Python Example):
```python
def twoSum(nums, target):
# Initialize HashMap to store indices
hashMap = {}
# Iterate through array
for i in range(len(nums)):
complement = target - nums[i]
# Check if complement exists in HashMap
if complement in hashMap:
return [hashMap[complement], i]
# Add current element and index to HashMap
hashMap[nums[i]] = i
# No solution found
return "No solution"
# Example usage
nums = [2, 7, 11, 15]
target = 9
result = twoSum(nums, target)
print("Indices:", result) # Output: Indices: [0, 1] (nums[0] + nums[1] = 9)
```
This implementation uses a HashMap to efficiently find the two numbers that add up to the target sum by checking for their complements. Adjust the input array `nums` and target sum `target` based on the actual problem requirements.



You are given an array of integers and a target sum. Write a function to find three numbers in the array that add up to the target sum. If such a triplet exists, return their indices. If no triplet is found, return “No solution”.
Input Format:
• An array of integers: [3, 2, 4, 8, 5, 9]
• Target sum: 15
Output Format:
• If a triplet is found: Indices of the three numbers that add up to the target sum.
• If no triplet is found: “No solution”.
Example:
Input:
Array: [3, 2, 4, 8, 5, 9]
Target Sum: 15
Output:
Indices: [0, 2, 3] # Numbers at indices 0, 2, and 3 (3, 4, and 8) add up to 15.
Adjust the input array and target sum based on the actual problem requirements.
Here are the steps to solve the Three Sum problem:
1. **Input Preparation**:
- Given an array of integers `nums` and a target sum `target`.
2. **Sort the Array**:
- Sort the array `nums` in non-decreasing order. This step is crucial for optimizing the algorithm.
3. **Initialize Result List**:
- Initialize an empty list `result` to store the triplets that sum up to the target.
4. **Iterate Through Array**:
- Iterate through each element in the sorted array `nums` up to the third-to-last element (to leave room for two pointers).
5. **Two Pointers Approach**:
- For each element `nums[i]`, initialize two pointers `left = i + 1` and `right = len(nums) - 1`.
- While `left < right`, perform the following steps:
- Calculate the current sum as `current_sum = nums[i] + nums[left] + nums[right]`.
- If `current_sum` equals `target`, add the triplet `[nums[i], nums[left], nums[right]]` to the `result` list.
- If `current_sum` is less than `target`, increment `left` to move towards larger values.
- If `current_sum` is greater than `target`, decrement `right` to move towards smaller values.
6. **Avoid Duplicates**:
- While iterating through `nums`, skip duplicate elements to avoid duplicate triplets in the result.
7. **Return Result**:
- After completing the iterations, return the `result` list containing all valid triplets that sum up to the target.
This implementation uses the two-pointers approach along with sorting and skipping duplicates to efficiently find all triplets in the array `nums` that sum up to the target sum `target`. Adjust the input array `nums` and target sum `target` based on the actual problem requirements.
Consider a database schema for a university that includes the following tables:
1. **Students**:
- student_id (Primary Key)
- name
- email
- department_id (Foreign Key referencing Departments table)
2. **Departments**:
- department_id (Primary Key)
- name
- location
3. **Courses**:
- course_id (Primary Key)
- name
- credits
- department_id (Foreign Key referencing Departments table)
Write SQL queries for the following scenarios:
1. Retrieve the names and emails of students who are enrolled in courses with more than 3 credits.
2. Update the location of the department with department_id = 101 to 'New Building'.
3. Insert a new course named 'Database Management' with 4 credits into the Computer Science department.
4. Delete all students from the 'Computer Science' department.
Your queries should be in standard SQL syntax.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?