Technical Study Ajay
رفتن به کانال در Telegram
Hello 👋 Friends Wellcome To My Telegram Channel 👍❤️🤗❤️❤️❤️❤️❤️🤗🤗🤗👍👍👍🤗
نمایش بیشتر2 796
مشترکین
+224 ساعت
+17 روز
-1530 روز
آرشیو پست ها
2 796
Warehouse Code
Python
TCS Codevita
Technical Study Ajay
def minimum_vehicles(weights, max_limit):
sorted_weights = sorted(filter(lambda x: x != 0, weights), reverse=True)
left, right = 0, len(sorted_weights) - 1
vehicles = 0
while left <= right:
if sorted_weights[left] + sorted_weights[right] <= max_limit:
right -= 1
left += 1
vehicles += 1
return vehicles
weights = list(map(int, input().split()))
max_limit = int(input())
result = minimum_vehicles(weights, max_limit)
print(result, end="")
Warehouse Code
Python
TCS Codevita
2 796
X from Y
C++ Language
Zone 2
TCS Codevita
Technical Study Ajay
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define placementlelo vector<int>
#define all(a) (a).begin() , (a).end()
#define sz(a) ((int)((a).size()))
const ll INF = 4e18;
vector<placementlelo> dp(1e4+1 , placementlelo(1e4+1 , -1));
int f(int i , int j , int s , int r , string &x , string &y , string &y1)
{
if(i>j)return 0;
if(dp[i][j] != -1)return dp[i][j];
int mini = 1e9;
for(int k=i; k<=j; k++)
{
if(y1.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , r+f(k+1 , j , s , r , x , y , y1));
if(y.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , s+f(k+1 , j , s , r , x , y , y1));
}
return mini;
}
int solve(int s , int r , string x, string y)
{
string y1 = y;
reverse(all(y1));
return f(0 , sz(x)-1 , s, r , x , y , y1);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string x , y;
cin >> x >> y;
int s, r;
cin >> s >> r;
int ans = solve(s , r, x , y);
if(ans==1e9){
cout<<"Impossible";
return 0;
}
cout << ans;
return 0;
}
X from Y
C++ Language
Zone 2
TCS Codevita
2 796
Chocolate Code
Python
TCS Codevita
Technical Study Ajay
def max_points(chocolates,initial):
chocolates=sorted(chocolates)
points=1
l=[1]
i=0
while i < len(chocolates):
if chocolates[i]<=initial:
initial=initial-chocolates[i]
points+=1
i+=1
else:
points-=1
initial+=chocolates[-1]
chocolates.pop()
l.append(points)
return max(l)
chocolates_list = list(map(int, input().split()))
initial_chocolates = int(input())
result = max_points(chocolates_list, initial_chocolates)
print(result,end="")
Chocolate Code
Python
TCS Codevita
2 796
Fencing Code
C++
TCS Codevita
Technical Study Ajay
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
x = abs(x);
y = abs(y);
x1 = abs(x1);
y1 = abs(y1);
x2 = abs(x2);
y2 = abs(y2);
int r1 = sqrt(((x1 - x) * (x1 - x)) + ((y1 - y) * (y1 - y)));
int r2 = sqrt(((x2 - x) * (x2 - x)) + ((y2 - y) * (y2 - y)));
int a1 = M_PI * r1 * r1;
int a2 = M_PI * r2 * r2;
if (a2 > a1)
{
int e = a2 - a1;
int f = sqrt(e);
int g = f * f;
int h = g - e;
int i = h * 20;
cout << "Krishna " << i;
}
else if (a1 > a2)
{
int p = a1 - a2;
int q = p * 20;
cout << "Shiva " << q;
}
else if (a1 == a2)
{
cout << "-1";
}
return 0;
}
Fencing Code
C++
TCS Codevita
2 796
No more Symbols
Python
TCS Codevita
Technical Study Ajay
def pfix(exq):
ta = []
ops = set(['+', '-', '*', '/', '%', '^'])
to = exq.split()
for t1 in reversed(to):
if t1.isdigit():
ta.append(int(t1))
elif t1 in ops:
if t1 == '^':
if len(ta) < 2:
return "expression is not complete or invalid"
ex1 = ta.pop()
be = ta.pop()
ta.append(ex1**be)
elif t1 == '/':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op1 // op2)
elif t1 == '%':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op2 % op1)
else:
if len(ta) < 2:
return "expression is not complete or invalid"
op1 = ta.pop()
op2 = ta.pop()
if t1 == '+':
ta.append(op1 + op2)
elif t1 == '-':
ta.append(op1 - op2)
elif t1 == '*':
ta.append(op1 * op2)
else:
return "expression is not complete or invalid"
if len(ta) == 1:
return ta[0]
else:
return "expression is not complete or invalid"
dn2 = {
"one":1,
"two":2,
"three":3,
"four":4,
"five":5,
"six":6,
"seven":7,
"eight":8,
"nine":9,
"zero":0
}
do1 = {
"add":'+',
"sub":'-',
"mul":'*',
"rem":'%',
"pow":'^'
}
def conv(s):
a1= s.split('c')
nx= 0
for i in a1:
if i in dn2:
nx = nx*10 + dn2[i]
else:
return "-1"
return str(nx)
s= input()
lee = s.split()
st = ""
flag = False
for i in lee:
if i not in do1:
jik = conv(i)
if jik=="-1":
flag = True
print("expression evaluation stopped invalid words present",end='')
break
st = st + jik + ' '
else:
st = st + do1[i] + ' '
if flag != True:
print(pfix(st),end='')
No more Symbols
Python
TCS Codevita
2 796
Orchad Code
Java
100% Working ✅
TCS Codevita
Technical Study Ajay
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String ashok = sc.nextLine();
String anand = sc.nextLine();
char as[] = ashok.toCharArray();
char an[] = anand.toCharArray();
int placementlelo_as=combination(as,as.length);
int placementlelo_an=combination(an,an.length);
if(placementlelo_as==0 && placementlelo_an==0)
System.out.print("Invalid input");
if(placementlelo_as>placementlelo_an)
System.out.print("Ashok");
else if(placementlelo_an > placementlelo_as)
System.out.print("Anand");
else
System.out.print("Draw");
}
static int combination(char arr[],int n)
{
int placementlelo=0;
String s="";
for(int i=0;i<n;i++)
{
s=""+arr[i];
for(int j=i+1;j<n;j++)
{
s+=arr[j];
if(s.charAt(0)!=arr[j])
{
for(int k=j+1;k<n;k++)
{
if(s.charAt(1)!=arr[k])
placementlelo++;
}
}
s=""+arr[i];
}
}
return placementlelo;
}
}
Orchad Code
Java
100% Working ✅
TCS Codevita
2 796
Repost from Technical Study Ajay
Hamming Distance
100% Working ✅
Java
TCS Codevita
YOUTUBE—> TECHNICAL STUDY AJAY
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);
}
}
}
private 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
100% Working ✅
Java
TCS Codevita
2 796
https://www.youtube.com/live/t-joUmVHIjE?si=M38qx2HkwkEgb6I8
सभी कोई sabscribe kar lo ab Code Upload ho raha hai YouTube pe.
2 796
Sports Day
Python
TCS Codevita
Technical Study Ajay
def ans(numbers):
numbers.sort()
n = len(numbers)
placementlelo = 0
for i in range(n):
efficiency = 0
priority = 1
for j in range(i, n):
efficiency += numbers[j] * priority
priority += 1
if efficiency > placementlelo:
placementlelo = efficiency
return placementlelo
numbers = list(map(int, input().split()))
result = ans(numbers)
if(result>0):
print(result, end="")
else:
print(0, end="")
Sports Day
Python
TCS Codevita
2 796
X from Y
C++ Language
Zone 2
TCS Codevita
Technical Study Ajay.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define placementlelo vector<int>
#define all(a) (a).begin() , (a).end()
#define sz(a) ((int)((a).size()))
const ll INF = 4e18;
vector<placementlelo> dp(1e4+1 , placementlelo(1e4+1 , -1));
int f(int i , int j , int s , int r , string &x , string &y , string &y1)
{
if(i>j)return 0;
if(dp[i][j] != -1)return dp[i][j];
int mini = 1e9;
for(int k=i; k<=j; k++)
{
if(y1.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , r+f(k+1 , j , s , r , x , y , y1));
if(y.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , s+f(k+1 , j , s , r , x , y , y1));
}
return mini;
}
int solve(int s , int r , string x, string y)
{
string y1 = y;
reverse(all(y1));
return f(0 , sz(x)-1 , s, r , x , y , y1);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string x , y;
cin >> x >> y;
int s, r;
cin >> s >> r;
int ans = solve(s , r, x , y);
if(ans==1e9){
cout<<"Impossible";
return 0;
}
cout << ans;
return 0;
}
X from Y
C++ Language
Zone 2
TCS Codevita
2 796
Hamming Distance
100% Working ✅
Java
TCS Codevita
YOUTUBE—> TECHNICAL STUDY AJAY
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);
}
}
}
private 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
100% Working ✅
Java
TCS Codevita
2 796
X from Y
Python Language
Zone 2
TCS Codevita
Technical Study Ajay 👈
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define placementlelo vector<int>
#define all(a) (a).begin() , (a).end()
#define sz(a) ((int)((a).size()))
const ll INF = 4e18;
vector<placementlelo> dp(1e4+1 , placementlelo(1e4+1 , -1));
int f(int i , int j , int s , int r , string &x , string &y , string &y1)
{
if(i>j)return 0;
if(dp[i][j] != -1)return dp[i][j];
int mini = 1e9;
for(int k=i; k<=j; k++)
{
if(y1.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , r+f(k+1 , j , s , r , x , y , y1));
if(y.find(x.substr(i , k-i+1)) != string::npos)mini = min(mini , s+f(k+1 , j , s , r , x , y , y1));
}
return mini;
}
int solve(int s , int r , string x, string y)
{
string y1 = y;
reverse(all(y1));
return f(0 , sz(x)-1 , s, r , x , y , y1);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string x , y;
cin >> x >> y;
int s, r;
cin >> s >> r;
int ans = solve(s , r, x , y);
if(ans==1e9){
cout<<"Impossible";
return 0;
}
cout << ans;
return 0;
}
X from Y
C++ Language
Zone 2
TCS Codevita
2 796
ROI
100% Working ✅
Python
TCS Codevita
n = int(input())
stocks = []
for _ in range(n):
a, b, c = map(int, input().split())
stocks.append((a, b, c))
m = int(input())
real = 0
unreal = 0
placementlelo = []
for i in range(n):
arr = [int(i) for i in input().split()]
placementlelo.append(arr)
day = int(input())
for i in range(n):
a, b, c = stocks[i]
if b > day: continue
elif c > day or not c: unreal += a * (placementlelo[i][day - 1] - placementlelo[i][b - 1])
else: real += a * (placementlelo[i][c - 1] - placementlelo[i][b - 1])
print(real)
print(unreal)
ROI
100% Working ✅
Python
TCS Codevita
2 796
Who is Lucky
Python Language
TCS Codevita
def toggle(num):
result = ""
for bit in num:
if bit == "0":
result += "1"
else:
result += "0"
return result
def get_max_sum(arr, k):
max_val = max(arr)
max_index = arr.index(max_val)
left = max(0, max_index-k)
right = min(len(arr)-1, max_index+k)
selected = arr[left:max_index+1] + arr[max_index:right+1]
arr = [x for x in arr if x not in selected]
return sum(selected), arr
# Input
arr = list(map(int, input().split()))
a1, b1 = input().split()
a2, b2 = input().split()
k = int(input())
sum1, sum2 = 0, 0
while arr:
s1, arr = get_max_sum(arr, k)
sum1 += s1
if not arr:
break
s2, arr = get_max_sum(arr, k)
sum2 += s2
if sum1 > sum2:
a1 = toggle(a1)
b2 = toggle(b2)
else:
a2 = toggle(a2)
b1 = toggle(b1)
xor1 = int(a1, 2) ^ int(b1, 2)
xor2 = int(a2, 2) ^ int(b2, 2)
if xor1 > xor2:
print("Rahul",end="")
elif xor2 > xor1:
print("Rupesh",end="")
else:
print("both",end="")
Who is Lucky
Python Language
TCS Codevita
2 796
/*
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Note:
0 ≤ x,y < 2^31.
Example:
Input: x = 1, y = 4
Output: 2
Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑
The above arrows point to positions where the corresponding bits are different.
*/
class Solution {
public int hammingDistance(int x, int y) {
int count = 0;
int n = x ^ y;
while (n > 0) {
n = n & (n - 1);
count++;
}
return count;
}
}
