Skip to content

Instantly share code, notes, and snippets.

@miyasinarafat
Created February 7, 2023 17:09
Show Gist options
  • Save miyasinarafat/5d2658b2efb0b9bd3bbbd34297f1e775 to your computer and use it in GitHub Desktop.
Save miyasinarafat/5d2658b2efb0b9bd3bbbd34297f1e775 to your computer and use it in GitHub Desktop.
Airwrk coding problems
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> inputs{1, 1, 2, 3, 3, 3, 4, 4, 5, 6};
auto arrSize = inputs.size();
for (int i = 0; i < arrSize; i++) {
if (inputs[i] == inputs[i+1]) {
int inputValue = inputs[i+1];
int swpValue = inputs[i+2];
inputs[arrSize-1] = inputValue;
inputs[i+1] = swpValue;
}
}
for (int i = 0; i < arrSize; ++i) {
cout << inputs[i] << "\n";
}
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> inputs{3, 0, 1};
// vector<int> inputs{0, 1}; PS, I am not able to find out the right implementation for this case.
sort(inputs.begin(), inputs.end());
for (int i = 1; i < inputs.size(); i++) {
if(inputs[i] != i) {
cout << i;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment