algorithms on NucuLabs
https://blog.nuculabs.dev/tags/algorithms/
Recent content in algorithms on NucuLabsNucuLabshttps://blog.nuculabs.dev/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E
https://blog.nuculabs.dev/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E
Hugo -- gohugo.ioen-usSat, 03 Jul 2021 22:32:20 +0000Tail Recursion
https://blog.nuculabs.dev/posts/2021/2021-07-03-tail-recursion/
Sat, 03 Jul 2021 22:32:20 +0000https://blog.nuculabs.dev/posts/2021/2021-07-03-tail-recursion/Hello everyone! ðŸ‘‹
Todayâ€™s article will be about tail recursion, a technique that allows you to optimize certain recursive functions.
Introduction In short, when you write a recursive function, each new call it does allocates a frame onto the stack. For example, let us take this following function:
private static long RecursiveFib(long n) { if (n <= 1) { return n; } return RecursiveFib(n - 1) + RecursiveFib(n - 2); } If we set a breakpoint at return n and call the function with RecursiveFib(10), we will get the following stack frame.LeetCode: Reverse Linked List Solution and Explanation
https://blog.nuculabs.dev/posts/2020/2020-11-17-leetcode-reverse-linked-list-solution/
Tue, 17 Nov 2020 22:59:44 +0000https://blog.nuculabs.dev/posts/2020/2020-11-17-leetcode-reverse-linked-list-solution/Hi,
In this article I will explain my solution for the following LeetCode problem: Reverse Linked List.
If youâ€™re interested in solving this problem then please try to spend at least one hour or more on it before looking at my solution.
To help you solve this problem Iâ€™ve created the following table:
Current Prev 1 NULL 2 1 3 2 NULL 3 Think about how you can use this table to write an iterative or recursive algorithm that reverses the linked list.LeetCode: Find The Town Judge
https://blog.nuculabs.dev/posts/2020/2020-05-11-leetcode-find-the-town-judge/
Mon, 11 May 2020 20:05:11 +0000https://blog.nuculabs.dev/posts/2020/2020-05-11-leetcode-find-the-town-judge/Hello
In this article I will present you my Python3 solution for the following problem which I found on LeetCode: find-the-town-judge.
Note: The solution is on the second page, so you wonâ€™t get spoiled if you want to attempt to solve the problem by yourself. Have fun!
from collections import defaultdict from typing import List """ In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.