Coder Vibes
15 subscribers
1 photo
1 file
5 links
Hi everyone! This community is for coding related discussions and helping each other.
Download Telegram
Channel created
Channel photo updated
import java.util.ArrayList;

public class Solution {

static long countMaximumSum(int n, ArrayList<Integer> arr) {
long maxSum = 0;

for (int i = 0; i < n; i++) {
long currentNum = arr.get(i);

for (int j = 0; j < n; j++) {
if (i != j && isPerfectSquare(currentNum) && isPerfectSquare(arr.get(j))) {
long newNum = 2 * (long) Math.sqrt(currentNum);
arr.set(i, (int) newNum);
arr.set(j, 0);
}
}

maxSum += arr.get(i);
}

return maxSum;
}

private static boolean isPerfectSquare(long num) {
long sqrt = (long) Math.sqrt(num);
return sqrt * sqrt == num;
}
}
import java.util.ArrayList;
import java.util.Collections;

public class Solution {
static long countMaximumSum(int n, ArrayList<Integer> arr) {
long sum = 0;
ArrayList<Integer> nonSquareIndices = new ArrayList<>();

for (int i = 0; i < n; i++) {
sum += arr.get(i);

// Check if A[i]*A[i] is not a square number
if (!isSquare(arr.get(i))) {
nonSquareIndices.add(i);
}
}

// Sort the non-square indices in descending order based on A[i]
Collections.sort(nonSquareIndices, (a, b) -> Integer.compare(arr.get(b), arr.get(a)));

// Perform the operation on the sorted non-square indices
for (int i : nonSquareIndices) {
int j = nonSquareIndices.get(0); // Choose the first non-square index
arr.set(i, (int) (2 * Math.sqrt(arr.get(i) * arr.get(j))));
arr.set(j, 0);
sum = Math.max(sum, calculateSum(arr));
}

return sum;
}

private static boolean isSquare(int num) {
int sqrt = (int) Math.sqrt(num);
return sqrt * sqrt == num;
}

private static long calculateSum(ArrayList<Integer> arr) {
long sum = 0;
for (int value : arr) {
sum += value;
}
return sum;
}
}
SELECT DISTINCT P.NAME AS PROFESSOR_NAME, C.NAME AS COURSE_NAME
FROM PROFESSOR P
JOIN SCHEDULE S ON P.ID = S.PROFESSOR_ID
JOIN COURSE C ON S.COURSE_ID = C.ID
WHERE C.DEPARTMENT_ID <> P.DEPARTMENT_ID;
import java.util.*;

class Result {
public static List<Integer> getTotalExecutionTime(int n, List<String> logs) {
List<Integer> executionTimes = new ArrayList<>();
Stack<Integer> stack = new Stack<>();
int[] exclusiveTimes = new int[n];
int prevTimestamp = 0;

for (String log : logs) {
String[] parts = log.split(":");
int functionId = Integer.parseInt(parts[0]);
String type = parts[1];
int timestamp = Integer.parseInt(parts[2]);

if (type.equals("start")) {
if (!stack.isEmpty()) {
exclusiveTimes[stack.peek()] += timestamp - prevTimestamp;
}
stack.push(functionId);
prevTimestamp = timestamp;
} else {
exclusiveTimes[stack.pop()] += timestamp - prevTimestamp + 1;
prevTimestamp = timestamp + 1;
}
}

for (int time : exclusiveTimes) {
executionTimes.add(time);
}

return executionTimes;
}
}
Anyone?
https://t.me/BitcoinWelfare_bot/app?startapp=tg_1159835330

🚀 Use the DreamStation bot to explore the unlimited potential of TON mining! 🌐

💎 Get the DSC token airdrop now!
💸 Round 1 rewards: +2000 DSC
⚡️ Boost +3 GH/s mining power, accelerate earnings quickly!
💎 Daily earnings: 133 $TON
https://t.me/AppGifts_bot/app?startapp=detail_40362319922

I WON $20! Click on the URL to help me win more! You can play and win too!! 💸💸