Comic Books
Python 3โ
Python 3โ
Flipkart
C++โ
C++โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
class SinglyLinkedListNode {
public:
int data;
SinglyLinkedListNode* next;
SinglyLinkedListNode(int node_data) {
this->data = node_data;
this->next = nullptr;
}
};
SinglyLinkedListNode* findLongestList(SinglyLinkedListNode* head) {
if (!head) return nullptr;
SinglyLinkedListNode* curr = head;
SinglyLinkedListNode* start = head;
SinglyLinkedListNode* bestStart = head;
int length = 1;
int bestLength = 1;
while (curr->next) {
if (curr->data >= curr->next->data) {
length++;
} else {
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
length = 1;
start = curr->next;
}
curr = curr->next;
}
// Check at the end in case the best sub-list is at the very end.
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
// Truncate the list after the longest non-increasing sub-list
SinglyLinkedListNode* temp = bestStart;
for (int i = 1; i < bestLength && temp; i++) {
temp = temp->next;
}
if (temp) {
temp->next = nullptr;
}
return bestStart;
}
C++โ
using namespace std;
class SinglyLinkedListNode {
public:
int data;
SinglyLinkedListNode* next;
SinglyLinkedListNode(int node_data) {
this->data = node_data;
this->next = nullptr;
}
};
SinglyLinkedListNode* findLongestList(SinglyLinkedListNode* head) {
if (!head) return nullptr;
SinglyLinkedListNode* curr = head;
SinglyLinkedListNode* start = head;
SinglyLinkedListNode* bestStart = head;
int length = 1;
int bestLength = 1;
while (curr->next) {
if (curr->data >= curr->next->data) {
length++;
} else {
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
length = 1;
start = curr->next;
}
curr = curr->next;
}
// Check at the end in case the best sub-list is at the very end.
if (length > bestLength) {
bestLength = length;
bestStart = start;
}
// Truncate the list after the longest non-increasing sub-list
SinglyLinkedListNode* temp = bestStart;
for (int i = 1; i < bestLength && temp; i++) {
temp = temp->next;
}
if (temp) {
temp->next = nullptr;
}
return bestStart;
}
C++โ
#include<bits/stdc++.h>
using namespace std;
vector<int> getMeanRankCount(vector<int>& rank) {
int n = rank.size();
vector<long long> prefixSum(n + 1, 0);
for (int i = 0; i < n; ++i) {
prefixSum[i + 1] = prefixSum[i] + rank[i];
}
vector<int> res(n, 0);
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
long long sum = prefixSum[j + 1] - prefixSum[i];
long long len = j - i + 1;
if (sum % len == 0) {
long long mean = sum / len;
if (mean <= n) {
res[mean - 1]++;
}
}
}
}
return res;
}
int main() {
vector<int> ranks = {4,7,3,6,5,2,1};
vector<int> result = getMeanRankCount(ranks);
for (int val : result) {
cout << val << " ";
}
return 0;
}
Amazon C++โ
using namespace std;
vector<int> getMeanRankCount(vector<int>& rank) {
int n = rank.size();
vector<long long> prefixSum(n + 1, 0);
for (int i = 0; i < n; ++i) {
prefixSum[i + 1] = prefixSum[i] + rank[i];
}
vector<int> res(n, 0);
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
long long sum = prefixSum[j + 1] - prefixSum[i];
long long len = j - i + 1;
if (sum % len == 0) {
long long mean = sum / len;
if (mean <= n) {
res[mean - 1]++;
}
}
}
}
return res;
}
int main() {
vector<int> ranks = {4,7,3,6,5,2,1};
vector<int> result = getMeanRankCount(ranks);
for (int val : result) {
cout << val << " ";
}
return 0;
}
Amazon C++โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include<bits/stdc++.h>
using namespace std;
vector<int> twoDimensions(vector<string> coordinates, int n) {
vector<int> maxAndCount(2);
vector<vector<int>> grid(n, vector<int>(n, 0));
int arrLength = coordinates.size();
int max_val = INT_MIN;
int count = 1;
for (int i = 0; i < arrLength; i++) {
stringstream ss(coordinates[i]);
int row, column;
ss >> row >> column;
for (int j = 0; j < row; j++) {
for (int k = 0; k < column; k++) {
grid[j][k] += 1;
if (grid[j][k] > max_val) {
max_val = grid[j][k];
count = 1;
} else if (grid[j][k] == max_val) {
count++;
}
}
}
}
maxAndCount[0] = max_val;
maxAndCount[1] = count;
return maxAndCount;
}
int main() {
vector<string> coors = { "2 3", "3 7", "4 1"};
vector<int> result = twoDimensions(coors, 7); // Change 3 to 7 for the grid size
cout <<result[1] << endl;
return 0;
}
Oracle โ
Growth in 2 Dimension
using namespace std;
vector<int> twoDimensions(vector<string> coordinates, int n) {
vector<int> maxAndCount(2);
vector<vector<int>> grid(n, vector<int>(n, 0));
int arrLength = coordinates.size();
int max_val = INT_MIN;
int count = 1;
for (int i = 0; i < arrLength; i++) {
stringstream ss(coordinates[i]);
int row, column;
ss >> row >> column;
for (int j = 0; j < row; j++) {
for (int k = 0; k < column; k++) {
grid[j][k] += 1;
if (grid[j][k] > max_val) {
max_val = grid[j][k];
count = 1;
} else if (grid[j][k] == max_val) {
count++;
}
}
}
}
maxAndCount[0] = max_val;
maxAndCount[1] = count;
return maxAndCount;
}
int main() {
vector<string> coors = { "2 3", "3 7", "4 1"};
vector<int> result = twoDimensions(coors, 7); // Change 3 to 7 for the grid size
cout <<result[1] << endl;
return 0;
}
Oracle โ
Growth in 2 Dimension
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
int64_t total_execution_time(vector<int> execution)
{
const auto n = execution.size();
map<int, int> div;
int64_t tot = 0;
for (auto tm : execution) {
if (!mp.count(tm)) {
mp[tm] = (tm + 1) / 2;
tot += tm;
} else {
tot += mp[tm];
mp[tm]=(mp[tm] + 1) / 2;
}
}
return tot;
}