/*
You have some apples and a basket that can carry up to 5000 units of weight.
Given an integer array weight where weight[i] is the weight of the ith apple,
return the maximum number of apples you can put in the basket.
Example 1:
Input: weight = [100,200,150,1000]
Output: 4
Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.
Example 2:
Input: weight = [900,950,800,1000,700,800]
Output: 5
Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.
*/
#include<bits/stdc++.h>
using namespace std;
int maxApples(vector<int> weight, int limit){
sort(weight.begin(), weight.end());
int count = 0, sum = 0, n = weight.size();
for(int i=0; i<n; i++){
sum+=weight[i];
if(sum>limit)break;
count++;
}
return count;
}
int main(){
vector<int> weight = {100,200,150,1000};
cout << maxApples(weight, 1450) << endl;
return 0;}
❤1
There are n windows open numbered from 1 to n, we want to simulate using alt + tab to navigate between the windows.
You are given an array windows which contains the initial order of the windows (the first element is at the top and the last one is at the bottom).
You are also given an array queries where for each query, the window queries[i] is brought to the top.
Return the final state of the array windows.
Example 1:
Input: windows = [1,2,3], queries = [3,3,2]
Output: [2,3,1]
Explanation:
Here is the window array after each query:
Initial order: [1,2,3]
After the first query: [3,1,2]
After the second query: [3,1,2]
After the last query: [2,3,1]
Example 2:
Input: windows = [1,4,2,3],
= [4,1,3]
Output: [3,1,4,2]
Explanation:
Here is the window array after each query:
Initial order: [1,4,2,3]
After the first query: [4,1,2,3]
After the second query: [1,4,2,3]
After the last query: [3,1,4,2]
Constraints:
1 <= n == windows.length <= 103
windows is a permutation of [1, n].
1 <= queries.length <= 103
1 <= queries[i] <= n
"""
Problem:
A string can be shortened by replacing any number of non-adjacent, non-empty substrings with their lengths (without leading zeros).
Examples of valid abbreviations:
"i12n" → (i mplementatio n)
"imp4n5n" → (imp leme n tatio n)
"14" → (implementation)
"implemetation" → (no substrings replaced)
Invalid abbreviations:
"i57n" → adjacent substrings replaced
"i012n" → leading zeros
"i0mplementation" → empty substring replaced
Your Task:
Given a word and an abbreviation abbr, return true if abbr correctly abbreviates word, otherwise return false.
A substring = a contiguous non-empty sequence of characters.
Examples
1.
Input: word = "apple", abbr = "a3e"
Output: true
2.
Input: word = "international", abbr = "i9l"
Output: false
3.
Input: word = "abbreviation", abbr = "abbreviation"
Output: true
Constraints
1 <= word.length <= 100
word contains only lowercase letters
1 <= abbr.length <= 100
abbr contains lowercase letters and digits
All digit substrings fit in a 32-bit integer #Leetcode_408_Premium
A string can be shortened by replacing any number of non-adjacent, non-empty substrings with their lengths (without leading zeros).
Examples of valid abbreviations:
"i12n" → (i mplementatio n)
"imp4n5n" → (imp leme n tatio n)
"14" → (implementation)
"implemetation" → (no substrings replaced)
Invalid abbreviations:
"i57n" → adjacent substrings replaced
"i012n" → leading zeros
"i0mplementation" → empty substring replaced
Your Task:
Given a word and an abbreviation abbr, return true if abbr correctly abbreviates word, otherwise return false.
A substring = a contiguous non-empty sequence of characters.
Examples
1.
Input: word = "apple", abbr = "a3e"
Output: true
2.
Input: word = "international", abbr = "i9l"
Output: false
3.
Input: word = "abbreviation", abbr = "abbreviation"
Output: true
Constraints
1 <= word.length <= 100
word contains only lowercase letters
1 <= abbr.length <= 100
abbr contains lowercase letters and digits
All digit substrings fit in a 32-bit integer #Leetcode_408_Premium
😨1
I am sending A2SV G7 interview questions which i got from u so u can practice similar question for your interview preparations if u want send or say share something u can send to me
Leetcode with dani pinned «I am sending A2SV G7 interview questions which i got from u so u can practice similar question for your interview preparations if u want send or say share something u can send to me»
Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".
A string is palindromic if it reads the same forward and backward.
Example 1:
Input: words = ["abc","car","ada","racecar","cool"]
A string is palindromic if it reads the same forward and backward.
Example 1:
Input: words = ["abc","car","ada","racecar","cool"]
Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.Today's question
Example 1:
Input: nums = [1,0,1,1,0]
Output: 4
Explanation:
- If we flip the first zero, nums becomes [1,1,1,1,0] and we have 4 consecutive ones.
- If we flip the second zero, nums becomes [1,0,1,1,1] and we have 3 consecutive ones.
The max number of consecutive ones is 4.
Example 2:
Input: nums = [1,0,1,1,0,1]
Output: 4
Explanation:
- If we flip the first zero, nums becomes [1,1,1,1,0,1] and we have 4 consecutive ones.
- If we flip the second zero, nums becomes [1,0,1,1,1,1] and we have 4 consecutive ones.
The max number of consecutive ones is 4.
Constraints:
1 <= nums.length <= 10**3
nums[i] is either 0 or 1.
Forwarded from ALX Ethiopia
The ALX x CodeLeague National Challenge was a huge success! Nearly 50 teams battled it out on Codeforces, celebrating top performers and first solvers. Big thanks to everyone who competed and pushed Ethiopian tech forward! 🚀🏆
#ALXEthiopia #CodeLeagueEthiopia #CompetitiveProgramming #Codeforces #DSA #ALXAfrica #LifeAtALX
#ALXEthiopia #CodeLeagueEthiopia #CompetitiveProgramming #Codeforces #DSA #ALXAfrica #LifeAtALX
⚡2
'''
You have some apples and a basket that can carry up to 5000 units of weight.
Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.
Example 1:
Input: weight = [100,200,150,1000]
Output: 4
Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.
Example 2:
Input: weight = [900,950,800,1000,700,800]
Output: 5
Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.
'''
weight = [100,200,150,5000]
def max_apple(weight):
left = 0
sum = 0
weight.sort()
while left < len(weight):
sum += weight[left]
if sum > 5000:
return left
else:
left +=1
return left
w = max_apple(weight)
print(w)
You have some apples and a basket that can carry up to 5000 units of weight.
Given an integer array weight where weight[i] is the weight of the ith apple, return the maximum number of apples you can put in the basket.
Example 1:
Input: weight = [100,200,150,1000]
Output: 4
Explanation: All 4 apples can be carried by the basket since their sum of weights is 1450.
Example 2:
Input: weight = [900,950,800,1000,700,800]
Output: 5
Explanation: The sum of weights of the 6 apples exceeds 5000 so we choose any 5 of them.
'''
weight = [100,200,150,5000]
def max_apple(weight):
left = 0
sum = 0
weight.sort()
while left < len(weight):
sum += weight[left]
if sum > 5000:
return left
else:
left +=1
return left
w = max_apple(weight)
print(w)