en
Feedback
WhiteHat Coding

WhiteHat Coding

Open in Telegram

Sharing = caring = spreading happiness

Show more
650
Subscribers
No data24 hours
-27 days
-330 days
Posts Archive
import java.util.HashMap; import java.util.Map; public class ConcertTicketBuyer {           private Map requirements = new HashMap<>();      private int funds;      public static void main(String[] args) {          ConcertTicketBuyer buyer = new ConcertTicketBuyer();          buyer.processInput();      }           public void processInput() {                   String[] input = {              "16",              "REQUIREMENT 11 100 12",              "DATA 11",              "DATA 11 DATA 1 110",              "DATA 13",              "DATA 13 DATA 100",              "DATA 21",              "DATA 21 DATA 150",              "DATA 290",              "DATA 23",              "DATA 23",              "DATA 100",              "DATA 0",              "DATA 0",              "DATA 0",              "DATA 0"          };          int currentIndex = 1;          int totalRequirements = Integer.parseInt(input[0]);          while (currentIndex < input.length) {              String line = input[currentIndex++];              String[] tokens = line.split(" ");              if (tokens[0].equals("REQUIREMENT")) {                  int artistId = Integer.parseInt(tokens[1]);                  int locationId = Integer.parseInt(tokens[2]);                  int maxPrice = Integer.parseInt(tokens[3]);                  int minCategory = Integer.parseInt(tokens[4]);                  int minSeats = Integer.parseInt(tokens[5]);                  requirements.put(artistId, new Requirement(locationId, maxPrice, minCategory, minSeats));              } else if (tokens[0].equals("DATA")) {                  int messageId = Integer.parseInt(tokens[1]);                  String data = tokens[2];                  processEventData(messageId, data);              }          }      }      // Process incoming event data      public void processEventData(int messageId, String data) {          if (data.equals("0")) {                           return;          }                   String[] tokens = data.split(" ");          int artistId = Integer.parseInt(tokens[0]);          int locationId = Integer.parseInt(tokens[1]);          int ticketPrice = Integer.parseInt(tokens[2]);          int category = Integer.parseInt(tokens[3]);          int availableSeats = Integer.parseInt(tokens[4]);          Requirement requirement = requirements.get(artistId);          if (requirement != null && meetsCriteria(requirement, ticketPrice, category, availableSeats)) {                           int numTicketsToBuy = requirement.getMinSeats();              funds -= (numTicketsToBuy * ticketPrice);              System.out.println("Buy " + numTicketsToBuy + " tickets for artist " + artistId + " at location " + locationId);          }      }          public boolean meetsCriteria(Requirement requirement, int ticketPrice, int category, int availableSeats) {          return ticketPrice <= requirement.getMaxPrice()                  && category >= requirement.getMinCategory()                  && availableSeats >= requirement.getMinSeats()                  && funds >= (requirement.getMinSeats() * ticketPrice);      }      private static class Requirement {          private int locationId;          private int maxPrice;          private int minCategory;          private int minSeats;          public Requirement(int locationId, int maxPrice, int minCategory, int minSeats) {              this.locationId = locationId;              this.maxPrice = maxPrice;              this.minCategory = minCategory;              this.minSeats = minSeats;          }          public int getLocationId() {              return locationId;          }          public int getMaxPrice() {              return maxPrice;          }          public int getMinCategory() {              return minCategory;          }          public int getMinSeats() {              return minSeats;          }      } }

photo content
+1

If the exam questions are same for all oct 9th guys … then it would be easy to help you 🦋💙🙏🏻 Share @whitehatcoding❤️✅

Some basic Questions regarding the assessment Question 1 - Can we give the assessment again on 30th Oct/ 6 nov, if we select for 9th October? Answer - No, U can only attempt it once either 9th oct or 30th/6th nov. Question 2 - What will be the pattern? Answer - 2 Java Questions, 2 SQL queries, 15 MCQs ( from Basic web fundamentals n Java , SQL concepts) Question 3 - What if you are not able to clear the assessment? Answer - You will NOT BE revoked but your onboarding will be delayed & delay period depends upon business requirements so it can be of 1 month or upto 6+ months also. Question 4 - When your CSD training will start? Answer - CSD training will gets started within 2-3 weeks of your Pre - assessment results. Question 5 - What will be assessment duration? Answer - it will a 3 hours duration. Morning slot time starts from 10 AM - 1 PM. Hope you got all your answers. If u have anymore ,feel free to ask. Share @whitehatcoding❤️✅

Cognizant Foundation assessment Pattern : 2 Java codes 2 SQL queries 12 Mcq

AnimatedSticker.tgs0.02 KB

#include <iostream> #include <vector> using namespace std; // Function to check if it's possible to transfer all diamonds in 'requiredTrips' trips with 'availableBoxes' boxes bool canTransfer(const vector<int>& diamonds, int requiredTrips, int availableBoxes) {     int tripsNeeded = 0;     int currentBoxCapacity = 0;     for (int diamond : diamonds) {         if (diamond > availableBoxes) {             // If a single pouch contains more diamonds than the boxes available, return false.             return false;         }         if (currentBoxCapacity + diamond <= availableBoxes) {             // If we can add the diamonds from the current pouch to the current box, do so.             currentBoxCapacity += diamond;         } else {             // Otherwise, start a new trip with a new box.             tripsNeeded++;             currentBoxCapacity = diamond;         }     }     // Check if the trips needed are within the limit 'requiredTrips'.     return tripsNeeded < requiredTrips; } int main() {     int numberOfDiamonds, trips;     cin >> numberOfDiamonds; // Input size of the array     vector<int> diamondWeights(numberOfDiamonds);     for (int i = 0; i < numberOfDiamonds; i++) {         cin >> diamondWeights[i]; // Input the array elements     }     cin >> trips; // Input the number of trips     int minimumBoxes = 1; // Minimum possible boxes     int maximumBoxes = numberOfDiamonds; // Maximum possible boxes     while (minimumBoxes < maximumBoxes) {         int middleBoxes = minimumBoxes + (maximumBoxes - minimumBoxes) / 2;         if (canTransfer(diamondWeights, trips, middleBoxes)) {             // If it's possible to transfer all diamonds in 'trips' trips with 'middleBoxes' boxes,             // we can try to reduce the number of boxes.             maximumBoxes = middleBoxes;         } else {             // Otherwise, we need more boxes, so we increase the number of boxes to consider.             minimumBoxes = middleBoxes + 1;         }     }     // The 'minimumBoxes' variable now contains the minimum number of boxes required.     cout << minimumBoxes << endl;     return 0; } "DIAMOND BOX" AMAZON HACKON OA ROUND 2 CODE VERIFIED 🥰 Share @coding_000❤️✅

#include <iostream> #include <vector> #include <unordered_map> // Include the unordered_map header using namespace std; int findMaxSum(int n, int elements[], int k) {     // Adjust elements to make them odd     for (int i = 0; i < n; i++) {         if (elements[i] % 2 == 0) {             elements[i] = elements[i] - 1;         }     }          unordered_map<int, int> elementFrequency;     int currentSum = 0, maxSum = 0;     int left = 0, right = 0;     // Calculate the initial sum and frequency     while (right < k && right < n) {         currentSum += elements[right];         elementFrequency[elements[right]]++;         right++;     }     if (elementFrequency.size() == k) {         maxSum = currentSum;     }     // Sliding window technique     while (right < n) {         elementFrequency[elements[right]]++;         elementFrequency[elements[left]]--;         if (elementFrequency[elements[left]] == 0) {             elementFrequency.erase(elements[left]);         }         currentSum += elements[right];         currentSum -= elements[left];         if (elementFrequency.size() == k) {             maxSum = max(maxSum, currentSum);         }         left++;         right++;     }     return maxSum; } int main() {     int n;     cin >> n;     int elements[n];     for (int i = 0; i < n; i++) {         cin >> elements[i];     }     int k;     cin >> k;     int result = findMaxSum(n, elements, k);     cout << result << endl;     return 0; } "MINIMUM COST(VECTOR)" AMAZON HACKON OA ROUND 2 CODE VERIFIED 🥰 Share @coding_000❤️

#include <iostream> #include <map> #include <cmath> using namespace std; #define MOD 998244353 map<long long, long long> frequencyMap; long long fastExponentiation(long long base, long long exponent) {     long long result = 1;     base = base % MOD;     while (exponent) {         if (exponent % 2)             result = (result * base) % MOD;         base = (base * base) % MOD;         exponent >>= 1;     }     return result; } int main() {     long long n, inputValue, isAllZeros = 1, maxInputValue = 0;     long long answer = 1;     cin >> n;     for (long long i = 0; i < n; i++) {         cin >> inputValue;         frequencyMap[inputValue]++;         maxInputValue = max(maxInputValue, inputValue);                  if ((i == 0 && inputValue != 0) || (i != 0 && inputValue == 0))             isAllZeros = 0;     }     if (isAllZeros) {         for (long long i = 1; i <= maxInputValue; i++) {             answer = (answer % MOD * fastExponentiation(frequencyMap[i - 1], frequencyMap[i]) % MOD) % MOD;         }         cout << answer % MOD << endl;     } else {         cout << 0 << endl;     }     return 0; } "TREE" AMAZON HACKON OA ROUND 2 CODE VERIFIED 🥰

#include <iostream> #include <vector> #include <unordered_map> // Include the unordered_map header using namespace std; int solve(int n, int arr[], int k) { // Change the array parameter declaration     for (int i = 0; i < n; i++) {         if (arr[i] % 2 == 0) {             arr[i] = arr[i] - 1;         }     }     unordered_map<int, int> mp;     int currentSum = 0, maxSum = 0;     int left = 0, i = 0;     while (i < k && i < n) {         currentSum += arr[i];         mp[arr[i]]++;         i++;     }     if (mp.size() == k) {         maxSum = currentSum;     }     for (int i = k; i < n; i++) {         mp[arr[i]]++;         mp[arr[left]]--;         if (mp[arr[left]] == 0) {             mp.erase(arr[left]);         }         currentSum += arr[i];         currentSum -= arr[left];         if (mp.size() == k) {             maxSum = max(maxSum, currentSum);         }         left++;     }     return maxSum; } int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {         cin >> arr[i];     }     int k;     cin >> k;     int ans = solve(n, arr, k); // Pass the array correctly     cout << ans << endl;     return 0; } " MAXSUM " AMAZON HACKON OA ROUND 2 CODE VERIFIED 🥰

AnimatedSticker.tgs0.02 KB

#include <iostream> #include <vector> #include <queue> using namespace std; struct Mouse {     int row, col, time;     Mouse(int r, int c, int t) : row(r), col(c), time(t) {} }; int countRemainingCheese(vector<vector<int>>& grid) {     int count = 0;     for (const auto& row : grid) {         for (int cell : row) {             if (cell == 1) {                 count++;             }         }     }     return count; } int findMinimumTimeToEatCheese(int N, vector<vector<int>>& grid) {     vector<vector<int>> directions = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};     vector<vector<bool>> visited(N, vector<bool>(N, false));     queue<Mouse> q;     // Find the mouse's initial position     int mouseRow = 0, mouseCol = 0;     for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {             if (grid[i][j] == 2) {                 mouseRow = i;                 mouseCol = j;             }         }     }     q.push(Mouse(mouseRow, mouseCol, 0));     visited[mouseRow][mouseCol] = true;     int cheeseEaten = 0;     int minTime = 0;     while (!q.empty()) {         Mouse currentMouse = q.front();         q.pop();         for (const auto& direction : directions) {             int newRow = currentMouse.row + direction[0];             int newCol = currentMouse.col + direction[1];             if (newRow >= 0 && newRow < N && newCol >= 0 && newCol < N && !visited[newRow][newCol]) {                 if (grid[newRow][newCol] == 1) {                     cheeseEaten++;                     minTime = currentMouse.time + 1;                     if (cheeseEaten == countRemainingCheese(grid)) {                         return minTime;                     }                 }                 if (grid[newRow][newCol] != 0) {                     visited[newRow][newCol] = true;                     q.push(Mouse(newRow, newCol, currentMouse.time + 1));                 }             }         }     }     return -1; // If all cheese cannot be eaten } int main() {     int N;     cin >> N;     vector<vector<int>> grid(N, vector<int>(N));     for (int i = 0; i < N; ++i) {         for (int j = 0; j < N; ++j) {             cin >> grid[i][j];         }     }     int minimumTime = findMinimumTimeToEatCheese(N, grid);     cout << minimumTime << endl;     return 0; } "CHEESE" AMAZON HACKON OA ROUND 2 CODE VERIFIED 🥰 VERIFIED

#include <iostream> #include <vector> using namespace std; int countWaysToDivideGarden(int N, vector<int>& mangoes) {     int totalWays = 0;     vector<int> cumulativeSum(N, 0);     // Calculate the cumulative sum of mangoes from left to right     cumulativeSum[0] = mangoes[0];     for (int i = 1; i < N; ++i) {         cumulativeSum[i] = cumulativeSum[i - 1] + mangoes[i];     }     // Iterate through possible split points     for (int splitIdx = 1; splitIdx < N - 1; ++splitIdx) {         int sumLeft = cumulativeSum[splitIdx];         int sumRight = cumulativeSum[N - 1] - cumulativeSum[splitIdx];         // Check if sumLeft + sumRight > sumCenter         if (sumLeft + sumRight > cumulativeSum[splitIdx]) {             totalWays++;         }     }     return totalWays; } int main() {     int numTestCases;     cin >> numTestCases;     while (numTestCases--) {         int numMangoes;         cin >> numMangoes;         vector<int> mangoWeights(numMangoes);         for (int i = 0; i < numMangoes; ++i) {             cin >> mangoWeights[i];         }         int waysToDivide = countWaysToDivideGarden(numMangoes, mangoWeights);         cout << waysToDivide << endl;     }     return 0; } "GARDEN" AMAZON HACKON OA ROUND 2 CODE VERIFIED

#include <iostream> #include <string> bool isVowel(char c) {     const std::string vowels = "aeiouAEIOU";     return vowels.find(c) != std::string::npos; } std::string addDollarAfterVowels(const std::string& input) {     std::string modifiedString;     bool consecutiveVowels = false;     for (size_t i = 0; i < input.length(); i++) {         modifiedString += input[i];         if (isVowel(input[i])) {             if (consecutiveVowels) {                 modifiedString += '$';                 consecutiveVowels = false; // Reset the flag             } else {                 consecutiveVowels = true;             }         } else {             consecutiveVowels = false;         }     }     return modifiedString; } int main() {     std::string input = "aabbeedpee";     std::string result = addDollarAfterVowels(input);     std::cout << result << std::endl;     return 0; } $ SIGN AMAZON HACKON OA ROUND 2 CODE VERIFIED

W, B, C = map(int,input().strip().split()) max_cars = min(W // 4, B, C // 2) print(max_cars) Python
W, B, C = map(int,input().strip().split()) max_cars = min(W // 4, B, C // 2) print(max_cars) Python

Backspace string compare code Share @whitehatcoding❤️
+1
Backspace string compare code Share @whitehatcoding❤️

Mitsogo Recruitment 2023 | Mitsogo technologies recruitment process 2023 https://www.mitsogo.com/career/software-engineer-fresher-hiring/

int countChar(string data, char coder) { &nbsp;&nbsp;&nbsp; int count = 0; &nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; data.len
+2
int countChar(string data, char coder) {     int count = 0;     for (int i = 0; i < data.length(); i++) {         if (data[i] == coder) {             count++;         }     }     return count; } Share @whitehatcoding❤️

Foundation skill readiness Pattern : 3 java coding questions 2 sql queries 12 mcqs