Skip to content
Paras Gupta

Jan 23 - Daily Programming Diary

Diary, Programming1 min read

1:00

Started posting the blogs and discovered a bug. The images stored will be stored according to the name given by the person who posts the image, causing collisions, and that's not what should happen in production. There are two ways to generate a unique ID.

  • Generating the ID based on timestamps, but this is not efficient with a large user base.
  • Using the UUID package which will definitely generate a randomized string.
1:30

Fixed the unique filename situation, and we are back on track. The only thing left to do is update the blogs and event images. Will be doing it after waking up.

Night night!

18:30

Slept a lot and starting the Leetcode Daily Challenge. The question seems to be more of an implementation problem than thee logic itself. I'm making the separate vectors for every diagonal and sorting them individually. After that, I'll put them back into the main matrix.

sort-the-matrix-diagonally.cpp
1vector<vector<int>> diagonalSort(vector<vector<int>> &mat) {
2 unordered_map<int, vector<int>> sorted_map;
3
4 for (int i = 0; i < mat.size(); i++) {
5 for (int j = 0; j < mat[i].size(); j++) {
6 if (sorted_map.find(i - j) == sorted_map.end()) {
7 vector<int> temp;
8 temp.push_back(mat[i][j]);
9 sorted_map[i - j] = temp;
10 } else {
11 sorted_map[i - j].push_back(mat[i][j]);
12 }
13 }
14 }
15
16 unordered_map<int, vector<int>>::iterator itr;
17
18 for (itr = sorted_map.begin(); itr != sorted_map.end(); itr++) {
19 sort(itr->second.begin(), itr->second.end());
20 }
21
22 for (int i = 0; i < mat.size(); i++) {
23 for (int j = 0; j < mat[i].size(); j++) {
24 mat[i][j] = sorted_map[i - j][0];
25 sorted_map[i - j].erase(sorted_map[i - j].begin());
26 }
27 }
28
29 return mat;
30}

Time complexity O(n*m) where n and m are the dimensions of the matrix. And space complexity is O(m+n)

21:45

Finally deployed the Raahee website after making the required changes to events and blogs. God, it's been some good 3 months.
Version 2.0 ✅

23:00

I guess that was it for today.

Bye!

EOD Checklist

  • Leetcode January Challenge
  • Raahee
  • This blog
© 2022 by Paras Gupta. All rights reserved.
Theme by LekoArts