I've just begun a 10-day coding challenge organized by Ingressive for Good and I'll be sharing my thoughts on Day 4 of the challenge.
Let me briefly describe how the challenge works before I share my experience with you. From September 21 through October 30, 2022, the challenge is to solve one common algorithm problem every day for ten days.
Today's algorithm problem was "The printing in order challenge " It is the 1114th algorithm challenge on "Leetcode.com".
Today's challenge was the most perplexing I have found since the contest began. The program's inability to execute in JavaScript was a problem in and of itself. Before I even understood what the question was attempting to say, I had to read it about ten times.
Here is the question:
Suppose we have a class:
public class Foo {
public void first() { print("first"); }
public void second() { print("second"); }
public void third() { print("third"); }
}
The same instance of Foo will be passed to three different threads. Thread A will call first(), thread B will call second(), and thread C will call third(). Design a mechanism and modify the program to ensure that second() is executed after first(), and third() is executed after second().
I'll now discuss my algorithm solving experience. I had to read up on the Python idea of threading in order to figure this out. Threading facilitates the execution of multiple tasks simultaneously and aids in the process flow of tasks.
Therefore, I created an event handler that would run after the first thread has finished.
This task was completed in Python, took 83 milliseconds to execute, and consumed about 14.5MB of memory.
Top comments (0)