LeetCode: Reverse Linked List Solution and Explanation

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....

November 17, 2020 · 3 min · Denis Nuțiu

Constructor Injection and Null Object Design Patterns

The Constructor Injection design pattern is a pattern that helps you declare all the required dependencies of a class in it’s constructor. This is useful because it helps you decouple the code, you can specify an interface instead of a concrete type, remember, program to an interface. Also, in the constructor it is easier to guard against null objects. The calling code doesn’t have to worry about null exceptions every time it uses a dependency....

November 7, 2020 · 2 min · Denis Nuțiu

Composition Root Pattern: How to Write Modular Software

The composition root is a design pattern which helps you structure a software application by implementing a class that builds all the other classes. In this example we will examine this pattern in Python. Here’s the object graph of the classes that we’re going to implement: I have designed a sample application that we’re going to use. It contains three components: ConsoleInputListener, ConsolePrinter and RomanianTranslator and a value object class: Message....

November 6, 2020 · 3 min · Denis Nuțiu

LeetCode: Flood Fill

Hello, Here’s my solution for the flood fill problem, found on LeetCode. If you want me to write about certain topics please let me know in the comments, thank you! Link to the problem: """ An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image....

July 16, 2020 · 2 min · Denis Nuțiu

Introduction to Pyenv for Linux Users

Hello, In this article I will introduce you to pyenv, a tool for managing python environments. Installing pyenv is pretty straight forward, you’ll need to clone the repo and add the binaries to the path. For a typical Debian based distro using the Zsh shell the instructions would be: git clone https://github.com/pyenv/pyenv.git ~/.pyenv echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc Then, in order for this to take effect, you need to reload the shell with: source ~/....

June 27, 2020 · 4 min · Denis Nuțiu

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....

May 11, 2020 · 2 min · Denis Nuțiu

LeetCode: Arrays 101: Inserting Items Into an Array

Hello, Here are my solutions for the second part of the card: Arrays 101, from LeetCode. Duplicate Zeroes Given an array of integers, remove duplicate zeroes and shift the remaining elements. class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """ index = 0 arr_length = len(arr) while index < arr_length: if arr[index] == 0: arr.insert(index, 0) arr.pop() index += 1 index += 1 Merge Sorted Array Given two sorted arrays, merge them together into nums1....

April 30, 2020 · 2 min · Denis Nuțiu

LeetCode: Arrays 101: Introduction &#8211; Solutions

Hello, LeetCode is a good place to practice programming by solving problems of all levels! After you solve a problem, you’ll get access to all submitted solutions, sorted by time and memory usage. That’s a nice way to compare your code to others and see what you did well and where you can improve. Here’s my solutions for the Arrays 101: Introduction card: Max Consecutive Ones class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: max_counter = 0 counter = 0 for i in nums: if i == 1: counter += 1 else: if counter > max_counter: max_counter = counter counter = 0 if counter > max_counter: max_counter = counter return max_counter Find Numbers with Even Number of Digits class Solution: @staticmethod def is_even(value): return len(str(value)) % 2 == 0 def findNumbers(self, nums: List[int]) -> int: return_value = 0 for number in nums: if self....

April 26, 2020 · 2 min · Denis Nuțiu

Nucu Car: Devlog 0x02

Hello, I’m still working on my NucuCar project from time to time, I’m currently at my parents home and I left the raspberry pi at my apartment so I’m only testing the builds it on my computer. Luckily I can test the telemetry by using the CPU temperature sensor implemented by dotnet IoT. For the next step, I wanted an effective way to store telemetry data in the cloud, preferably for free, since this is a hobby project after all....

April 19, 2020 · 3 min · Denis Nuțiu

LeetCode: Add Two Numbers Python 3 iterative solution

[Problem Link] Hello, Here’s my solution for the add two numbers problem on LeetCode. Example: <strong>Input:</strong> (2 -> 4 -> 3) + (5 -> 6 -> 4) <strong>Output:</strong> 7 -> 0 -> 8 <strong>Explanation:</strong> 342 + 465 = 807. When doing problems on websites such as LeetCode, I like to code in my own IDE, that’s why you’ll see some additional helper functions besides the solution code. class Solution(object): def _get_append_func(self, root): _root = root def __add_to_list(value): nonlocal _root _root....

March 15, 2020 · 2 min · Denis Nuțiu