— Diary, Programming — 2 min read
Woke up on time today (really!), and I thought "It's new year, let's build some habits.". I went ahead and completed the blog on Arch installation. Feels like a milestone to be honest. I mean it's great to have someone who's constantly asking you to complete a task.
I also decided to go ahead and start this blog as my daily programming journal. I think only I can hold myself accountable.
Installed Go. Wow the internet seems to want me to work today. xD
Just completed the Leetcode January Challenge Day 1. Although the problem seemed a bit challenging, I used hash table to store the first element of each piece with the respective vector. When I encounter the first number of a piece in array, I fetch the array and compare till the piece finishes.
1bool canFormArray(vector<int> &arr, vector<vector<int>> &pieces) {2 unordered_map<int, vector<int>> umap;3 for (int i = 0; i < pieces.size(); i++) {4 umap[pieces[i][0]] = pieces[i];5 }67 for (int i = 0; i < arr.size();) {8 if (umap.find(arr[i]) == umap.end()) {9 return false;10 } else {11 for (int j = 0; j < umap[arr[i]].size(); j++) {12 if (arr[i + j] == umap[arr[i]][j]) { }13 else {14 return false;15 }16 }17 i += umap[arr[i]].size();18 }19 }2021 return true;22}
The time complexity is O(n) even with the nested loop, and the space complexity is also O(n).
Optimization? Trade-off!: The hash table could be eliminated and sorting implemented which would take O(nlogn) time and O(1) space.
Break!
Helped Deepesh install arch on his PC, and failed miserably. I still don't know what went wrong. 🤦♂️
Okay, I'm back. Getting started with Codechef long challenge. This time they have 3 divisions and I feel like it's not really worth the effort to solve these questions, but you know I will probably get better questions next month. I'll just put the questions that I was able to solve today since it's a live contest and I don't want Codechef to ban me. Oh I have an idea, I'll post the submission IDs and Codechef will deny access until the contest ends. **pats on back!
Today's Questions:
I finally got around to working on the last task of the day. I'm exhausted but I thought, if not anything else, at least I should start making sense of the documentation.
Decided to write the traditional Hello World!
program and test stuff out.
1package main // For grouping functions23import "fmt" // Package for formatting text45func main() {6 fmt.Println("Hello World!"); // For printing7}
Weird things:
For what it's worth, it wasn't a complete disaster of a day. Godspeed.
Break
Gonna watch a movie now, and probably work on the Raahee report feature later. Hope I sleep on time today.
Started working on Raahee Reported content feature. Really tired today so entire focus on functionality right now!
Had to set up the project quite a lot, the small issues that projects have with dependencies. I just wanna sleep now! Anyway, I completed the data and display, just have to use it tomorrow to make a nice UI. For now, good night!