Skip to content

Commit c4da6d5

Browse files
authored
Merge branch 'main' into main
2 parents ab79efd + 9cbd61d commit c4da6d5

File tree

23 files changed

+568
-112
lines changed

23 files changed

+568
-112
lines changed

.github/workflows/check-duplicate-issues.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Problem Statement
2+
3+
Implement two classes: `Car` and `Boat` to handle different types of vehicles and return a formatted string describing their maximum speed.
4+
5+
### Input
6+
- `Car` constructor: Takes two arguments — maximum speed and the unit (either "km/h" or "mph").
7+
- `Boat` constructor: Takes one argument — maximum speed in knots.
8+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Define the Car class
2+
class Car:
3+
def __init__(self, max_speed, speed_unit):
4+
self.max_speed = max_speed
5+
self.speed_unit = speed_unit
6+
7+
def __str__(self):
8+
return f"Car with the maximum speed of {self.max_speed} {self.speed_unit}"
9+
10+
# Define the Boat class
11+
class Boat:
12+
def __init__(self, max_speed):
13+
self.max_speed = max_speed
14+
15+
def __str__(self):
16+
return f"Boat with the maximum speed of {self.max_speed} knots"
17+
18+
# Main function to take input and process the queries
19+
if __name__ == '__main__':
20+
q = int(input("Enter the number of queries: ")) # Number of queries
21+
for _ in range(q):
22+
args = input("Enter the vehicle type and its details: ").split() # Input query
23+
vehicle_type, params = args[0], args[1:]
24+
25+
if vehicle_type == "car":
26+
max_speed, speed_unit = int(params[0]), params[1]
27+
vehicle = Car(max_speed, speed_unit)
28+
elif vehicle_type == "boat":
29+
max_speed = int(params[0])
30+
vehicle = Boat(max_speed)
31+
else:
32+
raise ValueError("Invalid vehicle type")
33+
34+
# Print the string representation of the vehicle
35+
print(vehicle)
36+
37+
38+
39+
#Input example
40+
#Enter the number of queries: 2
41+
#Enter the vehicle type and its details: car 120 km/h
42+
#Car with the maximum speed of 120 km/h
43+
#Enter the vehicle type and its details: boat 82
44+
#Boat with the maximum speed of 82 knots
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function curcumfrence(r){
2+
console.log(Math.PI * r*r)
3+
}
4+
curcumfrence(prompt("Please enter a number "))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Problem Description
2+
Aryan is a small kid, and the circle is his favorite shape. Whenever he gets a number, he tries to find the area of a circle whose radius is that given number.
3+
4+
You are given a number `r` as an argument denoting the radius of the circle. You need to implement the function `findAreaOfCircle` which will return a number equal to the area of the circle with radius `r`. Given radius is always greater than 0.
5+
6+
**Hint 1:** The area of a circle is calculated using the formula: `Area = π * r * r` (where `r` is the radius of the circle).
7+
8+
**Hint 2:** Use `Math.PI` to get the value of pi.
9+
10+
11+
## Sample Input
12+
```plaintext
13+
3
14+
```
15+
16+
## Sample Output
17+
```plaintext
18+
28.274333882308138
19+
```
20+
21+
**Explanation:**
22+
Area of the circle = `Math.PI * 3 * 3 = 28.274333882308138`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.*;
2+
3+
public class CountBit {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
System.out.print("Enter a number: ");
7+
int n = sc.nextInt(); // Input a number
8+
int count = 0;// set a counter
9+
10+
// Loop to count the set bits in the binary representation of the number
11+
while (n > 0) {// Execute loop unlit no until num becomes 0
12+
count++;
13+
// This operation clears the rightmost set bit in n
14+
// Example: n = 1010 & 1001 clears the last '1' in binar
15+
n = n & (n - 1);
16+
}
17+
System.out.println("Total set bits: " + count);
18+
sc.close();
19+
}
20+
21+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Problem Statement
2+
Write a Java program to count the number of set bits (1s) in the binary representation of a given non-negative integer.
3+
4+
### Input
5+
- A single integer `n` where `0 <= n <= 10^9`.
6+
7+
### Output
8+
- The number of set bits (1s) in the binary representation of the integer.
9+
10+
### Example
11+
12+
#### Example 1:
13+
**Input**:
14+
`5`
15+
16+
**Output**:
17+
`2`
18+
19+
**Explanation**:
20+
Binary representation of 5 is `101`, which has 2 set bits.
21+
22+
#### Example 2:
23+
**Input**:
24+
`10`
25+
26+
**Output**:
27+
`2`
28+
29+
**Explanation**:
30+
Binary representation of 10 is `1010`, which has 2 set bits.
31+
32+
#### Example 3:
33+
**Input**:
34+
`0`
35+
36+
**Output**:
37+
`0`
38+
39+
**Explanation**:
40+
Binary representation of 0 is `0`, which has no set bits.
41+
42+
### Constraints
43+
- `0 <= n <= 10^9`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
You are given a 0-indexed array of integers nums, and an integer target.
2+
Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.
3+
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
4+
5+
Example 1:
6+
Input: nums = [1,2,3,4,5], target = 9
7+
Output: 3
8+
Explanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.
9+
10+
Example 2:
11+
Input: nums = [4,1,3,2,1,5], target = 7
12+
Output: 4
13+
Explanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution
5+
{
6+
public:
7+
int helper(int i, vector<int> &nums, int target, vector<vector<int>> &dp)
8+
{
9+
if (target < 0)
10+
return -1e5;
11+
if (target == 0)
12+
return 0;
13+
if (i == nums.size())
14+
return -1e5;
15+
16+
if (dp[i][target] != -1)
17+
return dp[i][target];
18+
int take = 1 + helper(i + 1, nums, target - nums[i], dp);
19+
int notTake = helper(i + 1, nums, target, dp);
20+
return dp[i][target] = max(take, notTake);
21+
}
22+
int lengthOfLongestSubsequence(vector<int> &nums, int target)
23+
{
24+
vector<vector<int>> dp(nums.size() + 1, vector<int>(target + 1, -1));
25+
int ans = helper(0, nums, target, dp);
26+
if (ans >= -1e5 && ans <= -1e4)
27+
return -1;
28+
return ans;
29+
}
30+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### Maximal Score After Applying K Operations
2+
3+
You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.
4+
In one operation:
5+
6+
choose an index i such that 0 <= i < nums.length,
7+
increase your score by nums[i], and
8+
replace nums[i] with ceil(nums[i] / 3).
9+
10+
Return the maximum possible score you can attain after applying exactly k operations.
11+
The ceiling function ceil(val) is the least integer greater than or equal to val.
12+
13+
### Example 1:
14+
15+
Input: nums = [10,10,10,10,10], k = 5
16+
Output: 50
17+
Explanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.
18+
19+
### Example 2:
20+
21+
Input: nums = [1,10,3,3,3], k = 3
22+
Output: 17
23+
Explanation: You can do the following operations:
24+
Operation 1: Select i = 1, so nums becomes [1,4,3,3,3]. Your score increases by 10.
25+
Operation 2: Select i = 1, so nums becomes [1,2,3,3,3]. Your score increases by 4.
26+
Operation 3: Select i = 2, so nums becomes [1,1,1,3,3]. Your score increases by 3.
27+
The final score is 10 + 4 + 3 = 17.
28+
29+
30+
31+
# Constraints:
32+
33+
- 1 <= nums.length, k <= 105
34+
- 1 <= nums[i] <= 109
35+

0 commit comments

Comments
 (0)