QualComm 1
QualComm 1
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
/* Round 4 */
// Integral image
// 0 1 1
// 1 1 1
// 1 2 1
// 0 1 2
// 1 3 5
// 2 6 9
ans[i][j] = sum;
}
}
return ans;
}
curColSum += input[i][j];
sum = curColSum + upperSum;
/*
for (int ansi = 0; ansi <= i; ansi++) {
for (int ansj = 0; ansj <= j; ansj++) {
sum += input[ansi][ansj];
}
}
*/
ans[i][j] = sum;
}
}
return ans;
}
int main() {
//ans = integralImage(input);
ans = integralImage_better(input);
return 0;
}
/* Round 1 question */
/
*************************************************************************
*****
*************************************************************************
******/
#include <iostream>
//Matrix mXn
// reshape(rXc) ->
// 3X3
// 1,2,3
// 4,5,6
// 1*9
vector<vector<int>> reshape(vector<vector<int>> inputMatrix, int row, int
col) {
//size check
int inputRow = inputMatrix.size();
if (inputRow != 0)
int inputCol = inputMatrix[0].size();
vector<vector<int>> ansMatrix;
if (c >= col) {
c = 0;
r++;
}
}
}
}
// Sorted arry
// 81, 4, 0, 9 36
// 0,4,9,36,81
// 0, 2, 6, 8, 10
// sorted version
// 0, 0,...
//Ans array
// -9, -2, 0, 3, 6, 0, 2, 6, 8, 10
//O(nlogn)
//i j
// -9, -2, 0, 3, 6,
vector<int> arrange(vector<int> in) {
// start from mod of min element
int minIndex = getMin(in);
// Start from min val index and traverse i,j opposite side
int i = minIndex - 1;
int j = minIndex + 1;
while (i >= 0 && j <= in.size()) {
if (abs(in[i] < abs(in[j]))) {
ans.push_back(in[i] * in[i]);
i--;
}
else { //abs(in[i] > abs(in[j]))
ans.push_back(in[j] * in[j]);
j++;
}
}
}
int main() {
return 0;
}
/* Round 2 */
// rotate Matrix
// Transpose
for (int i = 0; i < r; i++) {
for (int j = 0; j < i; j++) {
swap(in[i][j], in[j][i]
}
}
// Copy constructor
class sample {
int a;
public:
sample(int a) {
this->a = a;
}
sample(sample& s) {
this->a = s.a;
}
}
/* Round 3 */
// compress and decompress problem
// Count no of zeros before a no. Make pair of <zeroCount, number>
// Return array