Skip to content

Commit

Permalink
Added some code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeAbinash committed Jan 7, 2024
1 parent e75ceb8 commit 3ab16f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// by @codeAbinash
// Time : O(n)
// Space : O(1)

class Solution {
public:
int differenceOfSums(int n, int m) {
int sum1 = 0, sum2 = 0;
for (int i = 1; i <= n; i++) {
if (i % m == 0)
sum1 += i;
else
sum2 += i;
}
return sum2 - sum1;
}
};
22 changes: 22 additions & 0 deletions leetcode/problems/cpp/kth-smallest-element-in-a-sorted-matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// by @codeAbinash
// Time : O(nlogk)
// Space : O(k)

#include "queue"
#include "vector"

using namespace std;

class Solution {
public:
int kthSmallest(vector<vector<int>>& matrix, int k) {
priority_queue<int> pq;
for (auto row : matrix) {
for (auto num : row) {
pq.push(num);
if (pq.size() > k) pq.pop();
}
}
return pq.top();
}
};

0 comments on commit 3ab16f8

Please sign in to comment.