Code with Cisco OA Help : Interview Help
Ir al canal en Telegram
Codeforces Codechef Leetcode AtCoder GFG CodeStudio All Contests Solutions available.
Mostrar más916
Suscriptores
Sin datos24 horas
-47 días
+5530 días
Archivo de publicaciones
E solution
Find the smallest element index and if the array is sorted from there then print its index otherwise if not sorted print -1
void solve()
{
int n;
cin >> n;
vi arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
map freq;
for (int i = 0; i < n; i++)
freq[arr[i]]++;
int res = 0;
for (auto e : freq)
res += e.second * (e.second - 1) / 2;
res += freq[1] * freq[2];
cout << res << endl;
}
// D
// Here it is, enjoy❤️😁
D is also easy, just count the frequency of each element
Then add nC2 for every n belongs to frequency
and there is special case that 2^4 = 4^2 so just add the product of freq of 2 and freq of 4 😁❤️
B is brute force
Check for every factor of n
calculate max min for each one and find the max difference between them
if (n % 3)
cout << "First\n";
else
cout << "Second\n";
// A
D solution
Step 1
Push all elements in a single Vector
step 2
Sort it
step 3
consider 1-indexing and multiply each element with its index and add them
class Solution {
public:
long long maxSpending(vector>& values) {
vector items;
for (const auto& it : values) {
for (int x : it) {
items.push_back(x);
}
}
sort(items.begin(), items.end());
long long ans = 0;
long long d = 1;
for (int x : items) {
ans += d++ * static_cast(x);
}
return ans;
}
};
// D
https://leetcode.ca/2023-11-09-2927-Distribute-Candies-Among-Children-III/
Posted 2 days ago
Questions pehle hi out hogye the 😂
class Solution {
public:
long long distributeCandies(int n, int limit) {
auto comb2 = [](int n) {
return 1LL * n * (n - 1) / 2;
};
if (n > 3 * limit) {
return 0;
}
long long ans = comb2(n + 2);
if (n > limit) {
ans -= 3 * comb2(n - limit + 1);
}
if (n - 2 >= 2 * limit) {
ans += 3 * comb2(n - 2 * limit);
}
return ans;
}
};
// A and B both
¡Ya disponible! Investigación de Telegram 2025 — los principales insights del año 
