Skip to content
Paras Gupta

Jan 2 - Daily Programming Diary

Diary, Programming2 min read

7:50

Starting the day a little early than usual, but I am not really sure if I can get work done during daylight. Need to work on a bug that is causing the snackbar to show "invalid hook call". I'm pretty sure that has to do with reckless code adding without testing.

8:15

Yup, made a Higher Order Component to wrap the Add Event Component and called the hook there, passed the enqueueSnackbar down from there! React++ 😉

src/HOC/withSnackbar.jsx
1import React from 'react';
2import { useSnackbar } from 'notistack';
3
4const withSnackbar = (Component) => (props) => {
5 const { enqueueSnackbar } = useSnackbar();
6 return (
7 <Component {...props} enqueueSnackbar={enqueueSnackbar} />
8 );
9};
10
11export default withSnackbar;

This feels good!

Break;

10:50

After a long power cut, and significantly behind schedule, I'm back. First things first, trying to solve the 4th question BILLRD in Long Challenge.

11:30

Wow squares do help with collision. The trick? Well there can only be a maximum of 4 collisions no matter what. The Link to solution is 41071146.
Time to complete the Raahee reported content feature.

12:30

After an hour of overcoming the UI hurdles, I have a somewhat respectable UI for the cards and the details are being displayed properly. The only thing left is to wait for the action list.

14:00

Have been banging my head around the 5th problem on Codechef for a while now and I can't seem to get it. From what I gather, it's like the normal coin change problem but with same amount twice. Guess I'll have to go back to basics.
Well, on the Leetcode side, I completed the challenge Day 2 pretty quickly today. Had to find the corresponding nodes in a cloned tree, so it wasn't really difficult.

get-node-copy-from-clone.cpp
1TreeNode *getTargetCopy(TreeNode *original, TreeNode *cloned, TreeNode *target) {
2 if (original == NULL)
3 return NULL;
4
5 if (original == target) {
6 return cloned;
7 }
8
9 TreeNode *left = getTargetCopy(original->left, cloned->left, target);
10
11 if (left != NULL) {
12 return left;
13 }
14
15 TreeNode *right = getTargetCopy(original->right, cloned->right, target);
16
17 if (right != NULL) {
18 return right;
19 }
20
21 return NULL;
22}

Time complexity is O(n) where n is the number of nodes. Space complexity is O(n) if the tree is like a linked list.

I need a break!

16:40

Completely done with the Reported Content feature. Working alright! Used Material UI Snackbar notistack to create prompts. Looks awesome 👏

I also realized out that notistack already contains the withSnackbar. Bummer I mean, but at least I made it myself. I mean a lot of things are already coded, doesn't mean you can find them when you want.

17:10

Starting today's GoRoutine!
Aim : Creating a module and calling it from other module, helps in package publishing I guess. Following documentation.

17:50

Caveats with Go

  • First letter of function name defines if the function is public(capital letter) or private(small letter)
  • Requiring custom modules means building first, wow!
    Enough Go for today, it's a bit messed up!

It's 21:33 and I couldn't be any more tired, the day ends here. Could've been better but I'm satisfied with today.

EOD Checklist

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