Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Desert queen ✅
All test cases passed 💯
import java.util.*;
public class DesertPathfinder {
static class Cell implements Comparable<Cell> {
int row, col, waterCost;
Cell(int row, int col, int waterCost) {
this.row = row;
this.col = col;
this.waterCost = waterCost;
}
@Override
public int compareTo(Cell other) {
return Integer.compare(this.waterCost, other.waterCost);
}
}
public static int calculateMinWater(char[][] grid, int gridSize) {
int[] rowOffsets = {-1, 1, 0, 0};
int[] colOffsets = {0, 0, -1, 1};
int[][] waterUsage = new int[gridSize][gridSize];
boolean[][] isVisited = new boolean[gridSize][gridSize];
for (int[] row : waterUsage) {
Arrays.fill(row, Integer.MAX_VALUE);
}
int startRow = -1, startCol = -1, endRow = -1, endCol = -1;
for (int row = 0; row < gridSize; row++) {
for (int col = 0; col < gridSize; col++) {
if (grid[row][col] == 'S') {
startRow = row;
startCol = col;
} else if (grid[row][col] == 'E') {
endRow = row;
endCol = col;
}
}
}
PriorityQueue<Cell> priorityQueue = new PriorityQueue<>();
priorityQueue.offer(new Cell(startRow, startCol, 0));
waterUsage[startRow][startCol] = 0;
while (!priorityQueue.isEmpty()) {
Cell current = priorityQueue.poll();
int currentRow = current.row;
int currentCol = current.col;
if (isVisited[currentRow][currentCol]) {
continue;
}
isVisited[currentRow][currentCol] = true;
if (currentRow == endRow && currentCol == endCol) {
return waterUsage[currentRow][currentCol];
}
for (int i = 0; i < 4; i++) {
int nextRow = currentRow + rowOffsets[i];
int nextCol = currentCol + colOffsets[i];
if (nextRow >= 0 && nextCol >= 0 && nextRow < gridSize && nextCol < gridSize
&& grid[nextRow][nextCol] != 'M' && !isVisited[nextRow][nextCol]) {
int newCost = waterUsage[currentRow][currentCol]
+ (grid[currentRow][currentCol] == 'T' && grid[nextRow][nextCol] == 'T' ? 0 : 1);
if (newCost < waterUsage[nextRow][nextCol]) {
waterUsage[nextRow][nextCol] = newCost;
priorityQueue.offer(new Cell(nextRow, nextCol, newCost));
}
}
}
}
return -1;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int gridSize = scanner.nextInt();
scanner.nextLine();
char[][] grid = new char[gridSize][gridSize];
for (int row = 0; row < gridSize; row++) {
String[] elements = scanner.nextLine().split(" ");
for (int col = 0; col < gridSize; col++) {
grid[row][col] = elements[col].charAt(0);
}
}
int result = calculateMinWater(grid, gridSize);
System.out.print(result);
scanner.close();
}
}
All test cases passed 💯
#include <bits/stdc++.h>
using namespace std;
int main() {
int rows, cols;
cin >> rows >> cols;
vector<vector<int>> matrix(rows, vector<int>(cols));
// Reading the matrix
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cin >> matrix[i][j];
}
}
int target;
cin >> target;
map<int, vector<pair<int, int>>> value_positions;
set<int> all_values;
// Mapping values to their positions in the matrix
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
int val = matrix[i][j];
value_positions[val].emplace_back(i, j);
all_values.insert(val);
}
}
set<int> affected_values;
// Identify values to be affected based on the target value's position
for (int i = 0; i < rows; ++i) {
vector<int> target_columns;
for (int j = 0; j < cols; ++j) {
if (matrix[i][j] == target) {
target_columns.push_back(j);
}
}
if (!target_columns.empty()) {
int max_col = *max_element(target_columns.begin(), target_columns.end());
for (int j = max_col + 1; j < cols; ++j) {
int val = matrix[i][j];
if (val != target) {
affected_values.insert(val);
}
}
}
}
set<int> remaining_values = all_values;
affected_values.erase(target);
int result_count = 0;
// Process the remaining values that are also in the affected set
for (auto value = affected_values.begin(); value != affected_values.end(); ++value) {
if (remaining_values.find(*value) != remaining_values.end()) {
remaining_values.erase(*value);
result_count++;
}
}
// Lambda function for further processing of the set of values
auto process_values = [&](const set<int>& current_values) -> set<int> {
set<int> final_values;
for (auto& val : current_values) {
for (auto& [pos, idx] : value_positions[val]) {
if (pos == rows - 1) {
final_values.insert(val);
break;
}
}
}
queue<int> value_queue;
for (auto& val : final_values) {
value_queue.push(val);
}
while (!value_queue.empty()) {
int front_value = value_queue.front();
value_queue.pop();
for (auto& val : current_values) {
if (final_values.find(val) != final_values.end()) continue;
bool is_connected = false;
for (auto& [row, col] : value_positions[val]) {
if (row + 1 < rows) {
int next_val = matrix[row + 1][col];
if (final_values.find(next_val) != final_values.end()) {
is_connected = true;
break;
}
}
}
if (is_connected) {
final_values.insert(val);
value_queue.push(val);
}
}
}
return final_values;
};
// Iteratively update the remaining values and count the result
while (true) {
set<int> processed_values = process_values(remaining_values);
set<int> values_to_remove;
for (auto& val : remaining_values) {
if (processed_values.find(val) == processed_values.end()) {
values_to_remove.insert(val);
}
}
if (values_to_remove.empty()) break;
for (auto& val : values_to_remove) {
remaining_values.erase(val);
result_count++;
}
}
cout << result_count;
return 0;
}
Block Extraction
All test cases passed 💯
import java.util.*;
public class RitikaTask {
private static int[] canFormWithDeletions(String sub, String mainStr, int maxDeletions) {
int i = 0, j = 0, deletionsUsed = 0;
while (i < mainStr.length() && j < sub.length()) {
if (mainStr.charAt(i) == sub.charAt(j)) {
i++;
j++;
} else {
deletionsUsed++;
if (deletionsUsed > maxDeletions) {
return new int[] {i, deletionsUsed};
}
i++;
}
}
return new int[] {i, deletionsUsed};
}
private static boolean canMatchCharacter(char c, List<String> substrings) {
for (String sub : substrings) {
if (sub.indexOf(c) >= 0) {
return true;
}
}
return false;
}
public static String solveRitikaTask(List<String> substrings, String mainStr, int k) {
int n = mainStr.length();
int deletionsUsed = 0;
StringBuilder formedString = new StringBuilder();
boolean isAnyMatch = false;
for (int i = 0; i < n; i++) {
if (!canMatchCharacter(mainStr.charAt(i), substrings)) {
return "Impossible";
}
}
for (int i = 0; i < n;) {
boolean matched = false;
for (String sub : substrings) {
int[] result = canFormWithDeletions(sub, mainStr.substring(i), k - deletionsUsed);
int newIndex = result[0];
int usedDeletions = result[1];
if (newIndex > 0) {
matched = true;
isAnyMatch = true;
formedString.append(mainStr.substring(i, i + newIndex));
i += newIndex;
deletionsUsed += usedDeletions;
break;
}
}
if (!matched) {
break;
}
}
if (formedString.length() == n) {
if (deletionsUsed <= k) {
return "Possible";
} else {
return formedString.toString().trim();
}
} else if (isAnyMatch) {
return "Nothing";
} else if (deletionsUsed > k) {
return formedString.toString().trim();
} else {
return formedString.toString().trim();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
scanner.nextLine();
List<String> substrings = new ArrayList<>();
for (int i = 0; i < N; i++) {
substrings.add(scanner.nextLine());
}
String mainStr = scanner.nextLine();
int K = scanner.nextInt();
String result = solveRitikaTask(substrings, mainStr, K);
System.out.print(result);
scanner.close();
}
}
HELP RITIKA CODE ✅✅✅
Language - Java
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
polygon using the Shoelace Theorem
int calculateArea(const vector<pair<int, int>>& polygon) {
int n = polygon.size();
int area = 0;
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
area += polygon[i].first * polygon[j].second;
area -= polygon[j].first * polygon[i].second;
}
return abs(area) / 2;
}
are connected
bool areConnected(pair<int, int> a, pair<int, int> b, pair<int, int>& p1, pair<int, int>& p2) {
return (p1 == a && p2 == b) || (p1 == b && p2 == a);
}
int main() {
int N;
cin >> N;
vector<pair<int, int>> coordinates;
vector<vector<pair<int, int>>> segments(N);
set<pair<int, int>> points;
store them as pairs
for (int i = 0; i < N; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
coordinates.push_back({x1, y1});
coordinates.push_back({x2, y2});
points.insert({x1, y1});
points.insert({x2, y2});
}
vector<pair<int, int>> polygon;
int maxArea = 0;
to form polygons
for (auto p1 = points.begin(); p1 != points.end(); ++p1) {
for (auto p2 = next(p1); p2 != points.end(); ++p2) {
polygon.push_back(*p1);
polygon.push_back(*p2);
maxArea = max(maxArea, calculateArea(polygon));
}
}
cout << maxArea << endl;
return 0;
}
Maximum Area - Codevita✅
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