DataStructure and Algorithms Solutions with Supercool 💯
前往频道在 Telegram
DSA with supercool For paid projects:- Email :- supercool7151@gmail.com Follow me on social media https://linktr.ee/codemaking
显示更多643
订阅者
无数据24 小时
无数据7 天
无数据30 天
帖子存档
https://topmate.io/uttamsingh/363169 for discount use this coupon Code_Making_100
If any one cracked there first round and wanna crack 2 round as well then book the slot fast only 100 students will get discount only
Problem Statement
There is a lottery in the next few days. There are N people standing in a line from 1,2,3....N to buy tickets to this lottery. It is given that each person will buy only one lottery ticket when they first buy a ticket from the lottery man.
However, everyone wants their chances to be as high as possible. Therefore, when the ith person buys some tickets, he will stand at the end of the line again to buy double the number of tickets that he previously bought.
You are given Q queries in an array Quer where in each query you are given an integer T (T= Quer[i]). The answer for each query is the index of
You are given Q queries in an array Quer where in each query you are given an integer T (T- Quer[i]). The answer for each query is the index of the person who will buy the ticket number T.
Solution :-
import java.util.*;
public class LotteryTickets { public static long sumOfTicketIndexes(int[] queries) {
long MOD = (long) 1e9 + 7; int maxQuery = Arrays.stream(queries).max().orElse(0);
int maxI = 1; while ((1 << maxI) - 1 <= maxQuery) {
maxI++; }
long result = 0;
for (int query : queries) { int i = 1;
while ((1 << (i - 1)) <= query) { i++;
} i--;
long X = query - (1 << (i - 1)) + 1; result += X;
result %= MOD; }
return result;
}
public static void main(String[] args) { int[] queries = {5, 10, 15};
long sum = sumOfTicketIndexes(queries); System.out.println("Sum of ticket indexes: " + sum);
}}
Your task is to find the sum of answers to all queries modulo 10^9+7.
Notes:
It is given that the lottery ticket will be sold in a series 1.2.3... and so on.
It is given that there are an infinite number of lottery tickets that can be sold.
You are given a string S of length N.
A substring is said to be having entropy if it meets the following requirements:
The length of the substring is at least 2
The frequency of the most frequent character in the substring is strictly more than half the length of the substring
A substring is said to be dominant if the substring has entropy and the size of the substring is the smallest among all such substrings.
Return the lexicographically smallest dominant substring or "ZERO" if there's no dominant substring.
Solution :-
public class DominantSubstring {
public static String findLexicographicallySmallestDominantSubstring(String S) {
int N = S.length();
int start = 0, end = 0;
Map freqMap = new HashMap<>();
int maxFreq = 0;
int minLength = N + 1;
int minStart = 0;
while (end < N) {
char ch = S.charAt(end);
freqMap.put(ch, freqMap.getOrDefault(ch, 0) + 1);
maxFreq = Math.max(maxFreq, freqMap.get(ch));
if (end - start + 1 >= 2 && maxFreq > (end - start + 1) / 2) {
if (end - start + 1 < minLength) {
minLength = end - start + 1;
minStart = start;
} else if (end - start + 1 == minLength) {
minStart = Math.min(minStart, start);
}
}
while (maxFreq > (end - start + 1) / 2 || end - start + 1 >= 2) {
char startCh = S.charAt(start);
freqMap.put(startCh, freqMap.get(startCh) - 1);
if (freqMap.get(startCh) == 0) {
freqMap.remove(startCh);
}
maxFreq = 0;
for (int freq : freqMap.values()) {
maxFreq = Math.max(maxFreq, freq);
}
if (end - start < minLength && maxFreq > (end - start) / 2) {
minLength = end - start;
minStart = start + 1;
} else if (end - start == minLength && maxFreq > (end - start) / 2) {
minStart = Math.min(minStart, start + 1);
}
start++;
}
end++;
}
if (minLength == N + 1) {
return "ZERO";
}
return S.substring(minStart, minStart + minLength);
}
public static void main(String[] args) {
String S = "abacabadabacaba";
String smallestDominantSubstring = findLexicographicallySmallestDominantSubstring(S);
System.out.println("Smallest Dominant Substring: " + smallestDominantSubstring);
}
}
You are given an array A of size N. You can do some operations on A.
In one operation you can do the following:
1) Select any two distinct index i and j of A.
2) Divide A[i] and A[j] by a common factor of A[i] and A[j].
You want to minimize the product of all the elements of A. You are allowed to perform the operation any number of times .
Let P denote the minimum possible product of all elements in A after applying the operations.
Find the value of P. Since the answer may be large return it modulo 10^9+7.
Input format:
1) the first line contains an integer, N, denoting the number of elements
2) each line i of the N subsequent lines(where 0<=i<=N) contains a long value describing A[i].
Constraints:
1<=N<=10^5
1<=A[i]<=10^9
Anyone have solution?
Solution
import java.util.*;
public class MinProductArray { public static long findMinProduct(long[] A) {
int N = A.length; long gcd = A[0];
for (int i = 1; i < N; i++) { gcd = findGCD(gcd, A[i]);
}
long result = 1; for (int i = 0; i < N; i++) {
A[i] = A[i] / gcd % (long) 1e9 + 7; result = (result * A[i]) % (long) 1e9 + 7;
}
return result; }
public static long findGCD(long a, long b) {
if (b == 0) { return a;
}
return findGCD(b, a % b);
}
public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
long[] A = new long[N]; for (int i = 0; i < N; i++) {
A[i] = scanner.nextLong(); }
long minProduct = findMinProduct(A);
System.out.println("Minimum Product: " + minProduct); }
}
how many students are giving the infosys test today
Mahindra Exam
Assessment - 2
Help Available
Msg: @SupercoolCoder
Low Cost 💰💰
Test Clearance Guaranteed ✅
Your Job Our Responsibility 😊
It’s not how you start, how you finish matters the most. Because it’s not over until it’s over.
keep the Josh High!
📌 Use these websites to practice coding exercises
➩hackerrank.com
➩topcoder.com
➩codewars.com
➩leetcode.com
➩projecteuler.net
➩hackerearth.com
➩coderbyte.com
➩codingame.com
➩exercism.org
➩edabit.com
➩codeforces.com
➩codechef.com
➩programiz.com
https://discord.gg/dgE7e5eW join this discord channel for mega links and free resources for it and cs students
Like share and subscribe this channel guys
Repost from N/a
Hello everyone!
I'm excited to announce my topmate.io page where you can book a 1:1 call or ask any queries you may have. Whether you need help with my areas of expertise, or just want to chat anything , I'm available.
I'm looking forward to hearing from you and helping you achieve your goals. Don't hesitate to reach out if you have any questions or just want to say hi!
Hello everyone!
I'm excited to announce my topmate.io page where you can book a 1:1 call or ask any queries you may have. Whether you need help with my areas of expertise, or just want to chat anything , I'm available.
I'm looking forward to hearing from you and helping you achieve your goals. Don't hesitate to reach out if you have any questions or just want to say hi!
