sanjay6969's blog

By sanjay6969, 6 weeks ago,

Is my approach correct? can anyone have more optimised approach?

my code:

#include <iostream> #include <vector> using namespace std; int main() { int signal_size; cin >> signal_size; vector<int> signals(signal_size); for (int i = 0; i < signal_size; ++i) { cin >> signals[i]; } int filter_A_sum = 0; int filter_B_sum = 0; int left = 0, right = signal_size - 1; bool is_A_turn = true; while (left <= right) { if (is_A_turn) { if (signals[left] > signals[right]) { filter_A_sum += signals[left]; ++left; } else { filter_A_sum += signals[right]; --right; } } else { if (signals[left] > signals[right]) { filter_B_sum += signals[left]; ++left; } else { filter_B_sum += signals[right]; --right; } } is_A_turn = !is_A_turn; } cout << filter_A_sum << endl; return 0; }
• -13

By sanjay6969, 6 weeks ago,

A network security company has an encryption algorithm which is used to encrypt and decrypt the company's sensitive data. The company wants to upgrade their decryption algorithm due to numerous cyber-attacks. Currently this new decryption algorithm is in the development phase, so the developers of the algorithm want to test it with the encrypted binary string. During the initial stage of the decryption process the new algorithm takes a list of binary strings consisting only of 0s and 1s and two integers X and Y. The decryption algorithm processes the list of binary strings in such a way that it displays the final decrypted message as the largest subset from the concatenated string which has at most X number of Os and at most Y number of 1s.

Write an algorithm for the decryption process to display the size of the largest subset which has at most X number of 0s and at most Y numbers of 1s.

Input The first line of the input consists of an integer- str_size, representing the total number of encrypted strings(N). The second line consists of N space-separated binary strings, representing the encrypted strings consisting only of 0s and 1s. The third line consists of an integer zeros_count, representing the maximum number of 0s in the decrypted message. The fourth line consists of an Integer ones_count, representing the maximum number of 1s in the decrypted message.

Output Print an integer representing the size of the largest subset which has at most X number of Os and at most Y number of 1s. Note A set A is a subset of another set B if all elements of A are also elements of B. A binary string is a string consisting of only 0s and 1s. The size of the largest subset is the total number of binary strings which are considered in the calculation of the final output.

Example
Input:
6
1 0 10 111 1100 1000
2
2

Output:
3
Explanation:
The largest subset with at most 2 0s and 2 1s are ("0", "1", '10"}, so the answer is 3.
• -3