2 952
Subscribers
No data24 hours
-47 days
-1230 days
Posts Archive
2 952
import java.util.Arrays;
public class MagicalStore {
static int maximum_toys(int cost[], int N, int K) {
int count = 0, sum = 0;
Arrays.sort(cost);
for (int i = 0; i < N; i++) {
if (sum + cost[i] <= K) {
sum = sum + cost[i];
count++;
}
}
return count;
}
public static void main(String[] args) {
int K = 50;
int cost[] = { 1, 12, 5, 111, 200, 1000, 10, 9, 12, 15 };
int N = cost.length;
System.out.print(maximum_toys(cost, N, K));
}
}
2 952
All answer available h dhundhna pdega agr exam clear krna h to
Mene sare answer send kr diye h already
2 952
def minimum_swaps(A):
# Count occurrences of each value
count = {}
for value in A:
if value in count:
count[value] += 1
else:
count[value] = 1
# Initialize variables to track current value and number of swaps needed
current_value = A[0]
current_count = 0
swaps_needed = 0
# Iterate through array
for value in A:
if value == current_value:
current_count += 1
else:
# Calculate number of swaps needed for current value
swaps_needed += count[current_value] - current_count
# Update current value and count
current_value = value
current_count = 1
# Calculate number of swaps needed for last value
swaps_needed += count[current_value] - current_count
return swaps_needed
2 952
Rohini Kinkar:
package com.ajit.String;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
String S = sc.next();
int result = solve(N, K, S);
System.out.println(result);
}
public static int solve(int N, int K, String S) {
int MOD = (int) Math.pow(10, 7);
Set<String> substrings = new HashSet<>();
for (int i = 0; i <= N - K; i++) {
substrings.add(S.substring(i, i + K));
}
int count = 0;
for (String substring : substrings) {
Set<String> permutations = new HashSet<>();
permute("", substring, permutations);
count += permutations.size();
count = count % MOD;
}
return count;
}
public static void permute(String prefix, String str, Set<String> permutations) {
int n = str.length();
if (n == 0) {
permutations.add(prefix);
} else {
for (int i = 0; i < n; i++) {
permute(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n), permutations);
}
}
return;
}
}
Permutations ☝️
2 952
#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
int findTicketBuyer(int T) {
int N = 1, index = 1;
while (N < T) {
N = N * 2;
index++;
}
return index;
}
int main() {
int Q;
cin >> Q;
long long int sum = 0;
for (int i = 0; i < Q; i++) {
int T;
cin >> T;
sum += findTicketBuyer(T);
sum %= MOD;
}
cout << sum << endl;
return 0;
}
2 952
def kthSteppingNumber(N, k):
queue = [N]
count = 0
while queue:
curr = queue.pop(0)
if isSteppingNumber(curr):
count += 1
if count == k:
return curr
else:
for i in range(len(str(curr))):
for j in range(-1, 2):
new_num = int(str(curr)[:i] + str(int(str(curr)[i])+j) + str(curr)[i+1:])
if new_num > curr:
queue.append(new_num)
return -1
def isSteppingNumber(n):
n = str(n)
for i in range(1, len(n)):
if abs(int(n[i]) - int(n[i-1])) > 1:
return False
return True
N = 10
k = 3
print(kthSteppingNumber(N, k)) # Output: 12
2 952
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
int n;
cin >> n;
// Store the index of each element in the array
unordered_map<int, int> index;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
index[a[i]] = i;
}
// Initialize swaps variable
int swaps = 0;
// Iterate through the array
for (int i = 0; i < n; i++) {
// Check if current element is equal to next element
if (a[i] != a[i + 1]) {
// Find next occurrence of current element
int j = index[a[i]];
// Swap current element with next occurrence
swap(a[i], a[j]);
// Update index of current element
index[a[i]] = i;
// Update index of next occurrence
index[a[j]] = j;
// Increment swaps counter
swaps++;
}
}
cout << swaps << endl;
return 0;
}
2 952
Guys me sb ko send nhi kr paunga personally
Please check all answer available
And kuch answer or send kr rha hu chennal pr
2 952
// Infosys
// N flowers on a Recatangular pana
int ans = 100000000;
void solve(vector<int> a, int n, int k, int index, int sum,
int maxsum)
{
if (k == 1)
{
maxsum = max(maxsum, sum);
sum = 0; //https://t.me/It_7sem
for (int i = index; i < n; i++)
{
sum += a[i];
}
maxsum = max(maxsum, sum);
ans = min(ans, maxsum);
return;
}
sum = 0;
for (int i = index; i < n; i++)
{
sum += a[i];
maxsum = max(maxsum, sum);
solve(a, n, k - 1, i + 1, sum, maxsum);
}
}
int GetMaxBeauty(int N, int K, vector<int> A)
{
solve(A, N, K, 0, 0, 0);
return ans;
}
https://t.me/It_7sem
2 952
def getLargestString(s, k):
frequency_array = [0] * 26
for i in range(len(s)):
frequency_array[ord(s[i]) -
ord('a')] += 1
ans = ""
i = 25
while i >= 0:
if (frequency_array[i] > k):
temp = k
st = chr( i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
frequency_array[i] -= k
j = i - 1
while (frequency_array[j] <= 0 and
j >= 0):
j -= 1
if (frequency_array[j] > 0 and
j >= 0):
str1 = chr(j + ord( 'a'))
ans += str1
frequency_array[j] -= 1
else:
break
elif (frequency_array[i] > 0):
temp = frequency_array[i]
frequency_array[i] -= temp
st = chr(i + ord('a'))
while (temp > 0):
ans += st
temp -= 1
else:
i -= 1
return ans
if name == "main":
S = input()
k = 3
print (getLargestString(S, k))
Python
Bob code
INFOSYS EXAM ANS 10AM
ALL Slots are available
Telegram:- https://t.me/It_7sem
