#include <iostream>
#include <vector>
#include <algorithm>
int max_points(std::vector<int>& chocolates, int initial) {
std::sort(chocolates.begin(), chocolates.end());
int points = 0;
int max_points = 0;
for (int i = 0; i < chocolates.size(); ++i) {
if (chocolates[i] <= initial) {
initial -= chocolates[i];
points++;
max_points = std::max(max_points, points);
} else {
break;
}
}
return max_points;
}
int main() {
int n;
std::cin >> n; // Number of chocolates
std::vector<int> chocolates(n);
for (int i = 0; i < n; ++i) {
std::cin >> chocolates[i];
}
int initial_chocolates;
std::cin >> initial_chocolates; // Initial chocolates Bittu has
int result = max_points(chocolates, initial_chocolates);
std::cout << result;
return 0;
}
Chocolates code ✅✅
Share @Coding_000❤️
#include <vector>
#include <algorithm>
int max_points(std::vector<int>& chocolates, int initial) {
std::sort(chocolates.begin(), chocolates.end());
int points = 0;
int max_points = 0;
for (int i = 0; i < chocolates.size(); ++i) {
if (chocolates[i] <= initial) {
initial -= chocolates[i];
points++;
max_points = std::max(max_points, points);
} else {
break;
}
}
return max_points;
}
int main() {
int n;
std::cin >> n; // Number of chocolates
std::vector<int> chocolates(n);
for (int i = 0; i < n; ++i) {
std::cin >> chocolates[i];
}
int initial_chocolates;
std::cin >> initial_chocolates; // Initial chocolates Bittu has
int result = max_points(chocolates, initial_chocolates);
std::cout << result;
return 0;
}
Chocolates code ✅✅
Share @Coding_000❤️
👍1
Hamming Distance
Java
TCS Codevita
import java.util.Scanner;
public class HammingDistance {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
String binaryString = scanner.next();
int A = scanner.nextInt();
int B = scanner.nextInt();
int res = calculateHammingDistance(binaryString, A, B);
if(res == -1){
System.out.print("INVALID");
}
else{
System.out.print(res);
}
}
}
public static int calculateHammingDistance(String binaryString, int A, int B) {
int res = 0;
for (int i = 0; i < binaryString.length() - 1; i++) {
char ch = binaryString.charAt(i);
if(ch != '1' && ch != '0'){
return -1;
}
if(ch == '1'){
if(A < B){
if(i-1 >= 0 && binaryString.charAt(i-1) == '0'){
res += A;
}
else if(i+1 <= (binaryString.length()-1) && binaryString.charAt(i+1) == '0'){
res += B;
i++;
}
}
else{
if(i+1 <= (binaryString.length()-1) && binaryString.charAt(i+1) == '0'){
res += B;
i++;
}
else if( i-1 >= 0 &&binaryString.charAt(i-1) == '0'){
res += A;
}
}
}
}
return res;
}
}
Hamming Distance
Java
TCS Codevita
Java
TCS Codevita
import java.util.Scanner;
public class HammingDistance {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
String binaryString = scanner.next();
int A = scanner.nextInt();
int B = scanner.nextInt();
int res = calculateHammingDistance(binaryString, A, B);
if(res == -1){
System.out.print("INVALID");
}
else{
System.out.print(res);
}
}
}
public static int calculateHammingDistance(String binaryString, int A, int B) {
int res = 0;
for (int i = 0; i < binaryString.length() - 1; i++) {
char ch = binaryString.charAt(i);
if(ch != '1' && ch != '0'){
return -1;
}
if(ch == '1'){
if(A < B){
if(i-1 >= 0 && binaryString.charAt(i-1) == '0'){
res += A;
}
else if(i+1 <= (binaryString.length()-1) && binaryString.charAt(i+1) == '0'){
res += B;
i++;
}
}
else{
if(i+1 <= (binaryString.length()-1) && binaryString.charAt(i+1) == '0'){
res += B;
i++;
}
else if( i-1 >= 0 &&binaryString.charAt(i-1) == '0'){
res += A;
}
}
}
}
return res;
}
}
Hamming Distance
Java
TCS Codevita
🥰1
from sys import maxsize
def help(string):
n = len(string)
st = set()
st.add(string[0])
for i in range(1, n):
if string[i] == string[i - 1]:
continue
if string[i] in st:
return False
st.add(string[i])
return True
def minSwaps(string, l, r, cnt, minm):
if l == r:
if help(string):
return cnt
else:
return maxsize
for i in range(l + 1, r + 1, 1):
string[i], string[l] = string[l], string[i]
cnt += 1
x = minSwaps(string, l + 1, r, cnt, minm)
string[i], string[l] = string[l], string[i]
cnt -= 1
y = minSwaps(string, l + 1, r, cnt, minm)
minm = min(minm, min(x, y))
return minm
n = int(input())
alist = []
for i in input().split():
alist.append(i)
ans = minSwaps(alist, 0, n - 1, 0, maxsize)
print(ans)
Art_shift code
TCS CODEVITA✅
Python3
def help(string):
n = len(string)
st = set()
st.add(string[0])
for i in range(1, n):
if string[i] == string[i - 1]:
continue
if string[i] in st:
return False
st.add(string[i])
return True
def minSwaps(string, l, r, cnt, minm):
if l == r:
if help(string):
return cnt
else:
return maxsize
for i in range(l + 1, r + 1, 1):
string[i], string[l] = string[l], string[i]
cnt += 1
x = minSwaps(string, l + 1, r, cnt, minm)
string[i], string[l] = string[l], string[i]
cnt -= 1
y = minSwaps(string, l + 1, r, cnt, minm)
minm = min(minm, min(x, y))
return minm
n = int(input())
alist = []
for i in input().split():
alist.append(i)
ans = minSwaps(alist, 0, n - 1, 0, maxsize)
print(ans)
Art_shift code
TCS CODEVITA✅
Python3
🔥1
def ans(numbers):
numbers.sort()
n = len(numbers)
magic = 0
for i in range(n):
van = 0
priority = 1
for j in range(i, n):
van += numbers[j] * priority
priority += 1
if van > magic:
magic = van
return magic
numbers = list(map(int, input().split()))
result = ans(numbers)
if result > 0:
print(result, end="")
else:
print(0, end="")
Sports Day
Tcs codevita
numbers.sort()
n = len(numbers)
magic = 0
for i in range(n):
van = 0
priority = 1
for j in range(i, n):
van += numbers[j] * priority
priority += 1
if van > magic:
magic = van
return magic
numbers = list(map(int, input().split()))
result = ans(numbers)
if result > 0:
print(result, end="")
else:
print(0, end="")
Sports Day
Tcs codevita
❤2👍1🌚1
👍3
def shyam_and_strings(s1, s2, k):
n, m = len(s1), len(s2)
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
for j in range(m + 1):
if i == 0 or j == 0:
dp[i][j] = 0
else:
cnt = 0
if s1[i - 1] != s2[j - 1]:
cnt = min(abs(ord(s1[i - 1]) - ord(s2[j - 1])), 26 - abs(ord(s1[i - 1]) - ord(s2[j - 1])))
if cnt <= k:
dp[i][j] = 1 + dp[i - 1][j - 1]
dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]))
return dp[n][m]
s1 = input().strip()
s2 = input().strip()
k = int(input().strip())
if not s1 or not s2:
print(0)
else:
print(shyam_and_strings(s1, s2, k), end="")
Share @Coding_000✅❤️
n, m = len(s1), len(s2)
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
for j in range(m + 1):
if i == 0 or j == 0:
dp[i][j] = 0
else:
cnt = 0
if s1[i - 1] != s2[j - 1]:
cnt = min(abs(ord(s1[i - 1]) - ord(s2[j - 1])), 26 - abs(ord(s1[i - 1]) - ord(s2[j - 1])))
if cnt <= k:
dp[i][j] = 1 + dp[i - 1][j - 1]
dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]))
return dp[n][m]
s1 = input().strip()
s2 = input().strip()
k = int(input().strip())
if not s1 or not s2:
print(0)
else:
print(shyam_and_strings(s1, s2, k), end="")
Share @Coding_000✅❤️
🔥1👌1
This media is not supported in your browser
VIEW IN TELEGRAM
👉 VIRTUSA
Exam Help Available
Note: It's Paid 💰💰
Msg: @ILOVEU_143
Test Clearance Guaranteed👨💻✅
Share @Coding_000 ❤️😊
Exam Help Available
Note: It's Paid 💰💰
Msg: @ILOVEU_143
Test Clearance Guaranteed👨💻✅
Share @Coding_000 ❤️😊
👍2
👍2
Forwarded from Off Campus Updates | AMAZON | IBM | TCS | WIPRO | WILEY EDGE | VIRTUSA | MINDTREE | COGNIZANT (AMᎥGO)
Python Coding Notes ♥.pdf
5.7 MB
Python Coding Notes ♥.pdf
❤2🥰1
Oncampus & Offcampus
Exams Help Available
Msg: @ILOVEU_143✅
Note: It's Paid 💰💰
Test Clearance Guaranteed ✅
🔥To Apply For Latest Jobs and Internships and Offcampus links✅
🙋 Please Check 👇
https://t.me/Offcampus_000
Exams Help Available
Msg: @ILOVEU_143✅
Note: It's Paid 💰💰
Test Clearance Guaranteed ✅
🔥To Apply For Latest Jobs and Internships and Offcampus links✅
🙋 Please Check 👇
https://t.me/Offcampus_000
👍2
IMPORTANT REMINDER❗️
🔉Keep the channel UNMUTED to apply asap, else you might end up missing the opportunities by seeing the posts late. 🚨
These days competition is super high, people are applying in masses.
So, that's why we also don't know which posting gets closed when.
So.. apply fast >>>>>>>>
Keep @offcampus_000❤️ & @coding_000✅channel UNMUTED
🔉Keep the channel UNMUTED to apply asap, else you might end up missing the opportunities by seeing the posts late. 🚨
These days competition is super high, people are applying in masses.
So, that's why we also don't know which posting gets closed when.
So.. apply fast >>>>>>>>
Keep @offcampus_000❤️ & @coding_000✅channel UNMUTED
❤1👍1
Forwarded from Coding | EXAMS | IBM ACCENTURE | VIRTUSA | IBM | AMAZON | TCS | EPAM | WILEY EDGE | TECH MAHINDRA | JPMORGAN | HCL | WIPRO
Any one want projects -mini or Major 😊 Unique project💥💥
Domain AI/ML
contact -@ILOVEU_143 ❤️
Anyone need help in GRE and TOFEL, GMAT, DUOLINGO Exam help 👨💻👨💻
SOP , LOR, Resume ✍📝
Note -paid 🤑
share✅ share ✅@Coding_000
https://t.me/Finalyearprojectcse_Ml
Domain AI/ML
contact -@ILOVEU_143 ❤️
Anyone need help in GRE and TOFEL, GMAT, DUOLINGO Exam help 👨💻👨💻
SOP , LOR, Resume ✍📝
Note -paid 🤑
share✅ share ✅@Coding_000
https://t.me/Finalyearprojectcse_Ml
Telegram
Final Year Projects | Cse projects | AI /ML Projects
Main channel https://t.me/Coding_000
Contact Admin 👉 @ILOVEU_143 for booking your exam slots
Web- https://coding000.github.io/Projects/
💯% clearance in any placement exams
OffCampus -https://t.me/Offcampus_000
Discussion- https://t.me/exams_discussion
Contact Admin 👉 @ILOVEU_143 for booking your exam slots
Web- https://coding000.github.io/Projects/
💯% clearance in any placement exams
OffCampus -https://t.me/Offcampus_000
Discussion- https://t.me/exams_discussion
👍3
Cognizant hiring 2023 batch
Off campus Apply link 👇
https://app.joinsuperset.com/join/#/signup/student/jobprofiles/f207da4e-a7e1-48a0-b6ba-5f2fd6c719ca
👍5
Any one want projects -mini or Major 😊 Unique project💥💥
Domain AI/ML
contact -@ILOVEU_143 ❤️
Anyone need help in GRE and TOFEL, GMAT, DUOLINGO Exam help 👨💻👨💻
SOP , LOR, Resume ✍📝
We help to clear 👇👇
Any certification tests
Any internal exams
Note -paid 🤑
share✅ share ✅@Coding_000
Domain AI/ML
contact -@ILOVEU_143 ❤️
Anyone need help in GRE and TOFEL, GMAT, DUOLINGO Exam help 👨💻👨💻
SOP , LOR, Resume ✍📝
We help to clear 👇👇
Any certification tests
Any internal exams
Note -paid 🤑
share✅ share ✅@Coding_000
👍2
TCS CodeVita Round 1 results are out !!
Check Here: https://docs.google.com/spreadsheets/d/1zAHD9rn-yJhksE9hZcO0y-Q88BrLpvLcK-LM_6uYWlI/edit?usp=sharing
Have you cleared Round 1 ?
Check Here: https://docs.google.com/spreadsheets/d/1zAHD9rn-yJhksE9hZcO0y-Q88BrLpvLcK-LM_6uYWlI/edit?usp=sharing
Have you cleared Round 1 ?
👍2
How many of u want IBM Solutions..🆓🆓🆓😊👍👍
Share our channel make 5k 🎯
I will send all ans here....✅✅
Share our channel make 5k 🎯
I will send all ans here....✅✅
👍7❤3