MAXIMUM ROTATION
PYTHON
Maximum Rotation - Codevita ✅
PYTHON
def rl(layer, pos, dir, ol):
n = len(layer)
rot = [None] * n
if dir == "clockwise":
for i in range(n):
rot[(i + pos) % n] = layer[i]
else:
for i in range(n):
rot[(i - pos) % n] = layer[i]
for i in range(n):
if ol:
rot[i] = chr(((ord(rot[i]) - ord('A') - 1) % 26) + ord('A'))
else:
rot[i] = chr(((ord(rot[i]) - ord('A') + 1) % 26) + ord('A'))
return rot
def aq(pl, row, col, size):
layers = []
for layer in range(size // 2):
cl = []
for j in range(col + layer, col + size - layer):
cl.append(pl[row + layer][j])
for i in range(row + layer + 1, row + size - layer - 1):
cl.append(pl[i][col + size - layer - 1])
for j in range(col + size - layer - 1, col + layer - 1, -1):
cl.append(pl[row + size - layer - 1][j])
for i in range(row + size - layer - 2, row + layer, -1):
cl.append(pl[i][col + layer])
layers.append(cl)
for lidx, layer in enumerate(layers):
ol = (lidx + 1) % 2 == 1
dir = "counterclockwise" if ol else "clockwise"
pos = lidx + 1
rotated_layer = rl(layer, pos, dir, ol)
idx = 0
for j in range(col + lidx, col + size - lidx):
pl[row + lidx][j] = rotated_layer[idx]
idx += 1
for i in range(row + lidx + 1, row + size - lidx - 1):
pl[i][col + size - lidx - 1] = rotated_layer[idx]
idx += 1
for j in range(col + size - lidx - 1, col + lidx - 1, -1):
pl[row + size - lidx - 1][j] = rotated_layer[idx]
idx += 1
for i in range(row + size - lidx - 2, row + lidx, -1):
pl[i][col + lidx] = rotated_layer[idx]
idx += 1
def MAX_ROTATION(n, pl, queries):
for row, col, size in queries:
aq(pl, row, col, size)
result = ''.join(''.join(row) for row in pl)
return result
n = int(input())
pl = [list(input().strip().split()) for _ in range(n)]
q = int(input().strip())
queries = [tuple(map(int, input().strip().split())) for _ in range(q)]
result = MAX_ROTATION(n, pl, queries)
print(result, end="")
Maximum Rotation - Codevita ✅
from collections import deque
def infected_neighbors_count(grid, a, b):
n = len(grid)
count = 0
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(len(directions)):
dx, dy = directions[i]
nx, ny = a + dx, b + dy
if 0 <= nx < n and 0 <= ny < n and grid[nx][ny] == 1:
count += 1
return count
def infection_process(grid):
n = len(grid)
new_grid = [[grid[i][j] for j in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
neighbors = infected_neighbors_count(grid, i, j)
if grid[i][j] == 0 and neighbors == 3:
new_grid[i][j] = 1
elif grid[i][j] == 1 and (neighbors < 2 or neighbors > 3):
new_grid[i][j] = 0
return new_grid
def find_path(size, initial_grid):
grid = [[1 if cell == '1' else 0 for cell in row] for row in initial_grid]
start_x, start_y, end_x, end_y = -1, -1, -1, -1
def set_positions():
nonlocal start_x, start_y, end_x, end_y
for i in range(size):
for j in range(size):
if initial_grid[i][j] == 's':
start_x, start_y = i, j
grid[i][j] = 0
if initial_grid[i][j] == 'd':
end_x, end_y = i, j
grid[i][j] = 0
set_positions()
queue = deque([(start_x, start_y, grid, 0)])
seen_states = set()
while queue:
x, y, current_grid, days = queue.popleft()
if (x, y) == (end_x, end_y):
return days
state = (x, y, tuple(map(tuple, current_grid)))
if state in seen_states:
continue
seen_states.add(state)
next_grid = infection_process(current_grid)
moves = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]
for dx, dy in moves:
nx, ny = x + dx, y + dy
if 0 <= nx < size and 0 <= ny < size and next_grid[nx][ny] == 0:
queue.append((nx, ny, next_grid, days + 1))
return -1
if name == "main":
n = int(input())
pollution_map = [input().strip() for _ in range(n)]
print(find_path(n, pollution_map) + 1)
Plague 2050 - Codevita ✅
Import java.util.*;
public class LoopMaster {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int numberOfCommands = Integer.parseInt(scanner.nextLine());
List<String> commands = new ArrayList<>();
for (int i = 0; i < numberOfCommands; i++) {
commands.add(scanner.nextLine().trim());
}
processCommands(commands);
}
private static void processCommands(List<String> commands) {
Stack<Integer> loopIterations = new Stack<>();
Stack<Integer> currentIterations = new Stack<>();
StringBuilder output = new StringBuilder();
int commandIndex = 0;
while (commandIndex < commands.size()) {
String command = commands.get(commandIndex);
if (command.startsWith("for")) {
int times = Integer.parseInt(command.split(" ")[1]);
loopIterations.push(times);
currentIterations.push(0);
} else if (command.equals("do")) {
// No operation for "do"
} else if (command.equals("done")) {
int current = currentIterations.pop() + 1;
int maxIterations = loopIterations.pop();
if (current < maxIterations) {
loopIterations.push(maxIterations);
currentIterations.push(current);
commandIndex = findLoopStart(commands, commandIndex);
continue;
}
} else if (command.startsWith("break")) {
int breakCondition = Integer.parseInt(command.split(" ")[1]);
if (currentIterations.peek() + 1 == breakCondition) {
loopIterations.pop();
currentIterations.pop();
commandIndex = findLoopEnd(commands, commandIndex);
}
} else if (command.startsWith("continue")) {
int continueCondition = Integer.parseInt(command.split(" ")[1]);
if (currentIterations.peek() + 1 == continueCondition) {
int maxIterations = loopIterations.peek();
int current = currentIterations.pop() + 1;
if (current < maxIterations) {
currentIterations.push(current);
commandIndex = findLoopStart(commands, commandIndex);
}
continue;
}
} else if (command.startsWith("print")) {
String message = command.substring(command.indexOf("\"") + 1, command.lastIndexOf("\""));
output.append(message).append("\n");
}
commandIndex++;
}
System.out.print(output.toString());
}
private static int findLoopStart(List<String> commands, int currentIndex) {
int nestedLoops = 0;
for (int i = currentIndex - 1; i >= 0; i--) {
if (commands.get(i).equals("done")) {
nestedLoops++;
} else if (commands.get(i).equals("do")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return 0;
}
private static int findLoopEnd(List<String> commands, int currentIndex) {
int nestedLoops = 0;
for (int i = currentIndex + 1; i < commands.size(); i++) {
if (commands.get(i).equals("do")) {
nestedLoops++;
} else if (commands.get(i).equals("done")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return commands.size();
}
}
Loop Master - Codevita ✅
Please open Telegram to view this post
VIEW IN TELEGRAM
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<vector<pair<int, int>>> paths(n);
map<pair<int, int>, vector<int>> ptMap;
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int dx = x2 - x1, dy = y2 - y1;
int steps = max(abs(dx), abs(dy));
int sx = (dx == 0) ? 0 : dx / abs(dx);
int sy = (dy == 0) ? 0 : dy / abs(dy);
for (int j = 0; j <= steps; j++) {
int cx = x1 + sx * j;
int cy = y1 + sy * j;
paths[i].emplace_back(cx, cy);
ptMap[{cx, cy}].emplace_back(i);
}
}
string input, tgt;
getline(cin, input);
getline(cin, input);
unordered_map<string, int> valMap;
int pos = 0, len = input.size();
while (pos < len) {
size_t col = input.find(':', pos);
if (col == string::npos) break;
string key = input.substr(pos, col - pos);
pos = col + 1;
size_t sp = input.find(' ', pos);
if (sp == string::npos) sp = len;
int val = stoi(input.substr(pos, sp - pos));
valMap[key] = val;
pos = sp + 1;
}
cin >> tgt;
ll totalCost = 0;
for (auto &e : ptMap) {
if (e.second.size() >= 2) {
int cnt = e.second.size(), minCost = INT_MAX;
for (auto id : e.second) {
auto &p = paths[id];
size_t l = p.size();
size_t idx = find(p.begin(), p.end(), e.first) - p.begin();
int left = idx, right = l - idx - 1;
int cost = (left > 0 && right > 0) ? min(left, right) : max(left, right);
minCost = min(minCost, cost);
}
totalCost += (ll)cnt * minCost;
}
}
if (valMap.find(tgt) != valMap.end()) {
cout << (totalCost >= valMap[tgt] ? "Yes\n" : "No\n");
} else {
cout << "No\n";
}
int valid = 0, total = valMap.size();
for (auto &e : valMap) {
if (totalCost >= e.second) valid++;
}
double rate = (double)valid / total;
cout << fixed << setprecision(2) << rate;
return 0;
}
Fence voltage 👍
Share and add your friends too
https://t.me/code_alphix
💯 Plag & verified codes are posted
#Share_Now #Help_them
Stay tuned for more updates
@MRTRUELIVING_IX
@Mrtrueliving_ix
All Placement help available
https://t.me/code_alphix
💯 Plag & verified codes are posted
:change variables name's
#Share_Now #Help_them
Stay tuned for more updates
@MRTRUELIVING_IX
@Mrtrueliving_ix
All Placement help available
pair<double, double> r(double px, double py, double x1, double y1, double x2, double y2) {
double a = y2 - y1;
double b = x1 - x2;
double c = x2 * y1 - x1 * y2;
double d = (a * px + b * py + c) / sqrt(a * a + b * b);
double nx = px - 2 * d * (a / sqrt(a * a + b * b));
double ny = py - 2 * d * (b / sqrt(a * a + b * b));
return {nx, ny};
}
int main() {
double ar;
cin >> ar;
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
double s = sqrt(ar);
vector<pair<double, double>> cr = {
{0, 0},
{0, s},
{s, s},
{s, 0},
};
set<pair<double, double>> pts(cr.begin(), cr.end());
for (const auto& c : cr) {
auto [rx, ry] = r(c.first, c.second, x1, y1, x2, y2);
pts.insert({rx, ry});
}
for (const auto& p : pts) {
cout << fixed << setprecision(2) << p.first << " " << p.second << endl;
}
return 0;
}F.area
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
Please open Telegram to view this post
VIEW IN TELEGRAM
Form the string ✅
def form_str(n, subs, main):
m_len = len(main)
dp = [float('inf')] * (m_len + 1)
dp[0] = 0
for i in range(m_len + 1):
if dp[i] == float('inf'):
continue
for s, c in subs:
s_len = len(s)
max_olap = min(i, s_len)
for olap in range(max_olap + 1):
start = i - olap
end = start + s_len
if end > m_len:
continue
if start >= 0:
if main[start:i] == s[:olap]:
if main[i:end] == s[olap:]:
dp[end] = min(dp[end], dp[i] + c)
return "Impossible" if dp[m_len] == float('inf') else dp[m_len]
n = int(input())
subs = []
for _ in range(n):
ln = input().strip()
if not ln:
continue
parts = ln.split()
if len(parts) != 2:
w = " ".join(parts[:-1])
cost = int(parts[-1])
else:
w, cost = parts[0], int(parts[1])
subs.append((w, cost))
main = input().strip()
subs = [(s, c) for s, c in subs if s in main]
print(form_str(n, subs, main), end="")
AMDOCS ONCAMPUS help done ▶️ ✔️
Test accomplished▶️
All placement help available
OA HELP: @MRTRUELIVING_IX☄️
#Amdocs #ONCAMPUS #Done
Test accomplished
All placement help available
OA HELP: @MRTRUELIVING_IX
#Amdocs #ONCAMPUS #Done
Please open Telegram to view this post
VIEW IN TELEGRAM
https://app.joinsuperset.com/join/#/signup/student/jobprofiles/896ca255-1e49-462a-9991-abb6e8d1cbb7
Only for womens
Infor off campus - 2025 batch
Apply now
https://whatsapp.com/channel/0029VahiS3p2v1IyoS891Y1g/1347
Only for womens
Infor off campus - 2025 batch
Apply now
https://whatsapp.com/channel/0029VahiS3p2v1IyoS891Y1g/1347
Please open Telegram to view this post
VIEW IN TELEGRAM
void sort_students(struct Student arr[], int n) {
struct Student temp;
for (int i = 0; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
if (arr[i].score < arr[j].score ||
(arr[i].score == arr[j].score && strcmp(arr[i].first_name, arr[j].first_name) > 0) ||
(arr[i].score == arr[j].score && strcmp(arr[i].first_name, arr[j].first_name) == 0 && strcmp(arr[i].last_name, arr[j].last_name) > 0)) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}AMDOCS ✅
Please open Telegram to view this post
VIEW IN TELEGRAM
Oracle ✔️
Test accomplished ❤️
All placement help available
HELP: @MRTRUELIVING_IX
#ORACLE #ONcampus #Done▶️
Test accomplished ❤️
All placement help available
HELP: @MRTRUELIVING_IX
#ORACLE #ONcampus #Done
Please open Telegram to view this post
VIEW IN TELEGRAM