₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,795 members, 8,423,768 topics. Date: Wednesday, 10 June 2026 at 09:18 AM

Toggle theme

Namikaze's Posts

Nairaland ForumNamikaze's ProfileNamikaze's Posts

1 2 3 4 5 6 7 (of 7 pages)

ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 6:43am On Dec 25, 2022
+1 for neetcode
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 11:40am On Dec 24, 2022
my god grin grin
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 5:50pm On Dec 23, 2022
Sleekcode:
I strongly believe dropping questions will be far better than dropping resources.


Dropping just resources will see this thread lost in oblivion before New year just like your other threads.

No offense!
True the problems are what's gonna drive the thread, but resources shouldn't hurt, especially good reads like the one he posted.
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 5:49pm On Dec 23, 2022
qtguru:
Resource for the Day: Analysis of Algorithm
https://cs.lmu.edu/~ray/notes/alganalysis/
nice resource, should be a good refresher on analysis, thanks.
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 5:47pm On Dec 23, 2022
Sleekcode:
Must this be in python?

angry
no any language should do, just share a link to any online code editor so it's testable.
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 10:30am On Dec 23, 2022
airsaylongcome:
Lol! Now that that you mentioned trees, I remember learning about Binary Search Trees. And some tree algorithms about depth-first or breadth-first....it's been years man!
you actually did pretty good to even recall them back from 2003, I left my dsa course and daily practice for the hng internship and in just two months I've lost some of my edge.
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 10:27am On Dec 23, 2022
@qtguru
another suggestion
solutions to problems should not be posted here but on some kind of shareable online interpreter/compiler, so it's easier to test and also to tidy the thread, c++ is notorious for dirtying threads grin
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 10:25am On Dec 23, 2022
airsaylongcome:
Yes I fully understand that the Data Structures are completely different from the Algorithms. I was just a bit confused with qt's post that mentioned dealing with DSA first then Algo later
I sse, both terms are usually used exchangeably yes
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 10:23am On Dec 23, 2022
airsaylongcome:
Also before diving in to sharing problems (someone has already "gotten" to quicksort now now lol), I think it would be nice to give a background on the various data structures as well as the algorithms. It's been a few years I've been down the DSA route but if memory serves me right the DS were
Queues
Stack
Trees
(I don't recall learning Hash)
which were implemented with pointers and arrays.

The Algorithms if I remember correctly were split broadly into Search Algorithms and Sorting algorithms. Would be nice for someone to then list out the various search and sorting algorithms. I remember Bubble Sort and Insertion sort as well as Quick Sort. I'm literally pulling these stuff from my 2003 self. So over to the devs more in touch with all of the state of art info about DSA and put some clarity for folks reading
The data structures usually fall under arrays, linked lists, stacks, queues, maps and graphs, tree's are graphs, binary trees, binary search trees, self-balancing trees, heaps and tries are under tries. there's a special case of priority queues too.
The more complex data structures (minimum spanning trees, red black tree, quad tree) are almost always unordered are generally under trees and graphs.
There are many sorting algorithms, most common include selection, insertion, bubble, heap, merge and quick sorts. searching algorithms are usually just binary and linear, which work only for select data structures like arrays, linked lists and binary search trees.
There are more to algorithms than to searching and sorting, there are also algorithms for traversing trees/graphs, adding/deleting a node to trees e.t.c An algorithm is basically a step by step sequence of finite instructions that does a specific task, with this definition, a simple print statement is still an algorithm.
I agree, a sort of simple background on the most important data structures and algorithms would be good.
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 9:49am On Dec 23, 2022
airsaylongcome:
So let me get something right, a lot of you guys throw around acronyms that now seen confusing to me. My understanding is that

DSA stands for Data Structures and Algorithms
Algo stands for Algorithms

so when DSA and Algo are thrown together, I get a little confused because AFAIK the "A" in DSA is the same as Algo. Any more active devs wanna clarify?
yes your understanding is alright, though technically the DS and A/Algo are different, they're are usually used exchangeably because they coexist.
ProgrammingRe: I Want To Work At Google: Journey Of A Software Developer by namikaze: 9:24pm On Dec 22, 2022
AlchemyOfCodes:
Ok guys, finally done the exam. The good news is that I finally got into a DSA bootcamp where I get to rub shoulders with guys from Microsoft and the likes. The bad news my laptop suddenly crashed a day to my final papers.

When I charge the system, the indicator light blinks but the system will not boot. If anyone has an idea of what the issue is.

Right now , I will continue the DSA book on my phone.... At least one leetcode question everyday. Go back to my default mode of reading books. And hopefully I get it fixed soon. This thread ain't dying .
Which bootcamp is that?
ProgrammingRe: Algorithm And Data Structure Study Section by namikaze: 9:21pm On Dec 22, 2022
A suggestion, would be nice to have some dsa problems once in a while to solve, it should keep the thread busy if the problems are interesting enough.
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 8:58pm On Dec 22, 2022
GREATIGBOMAN:
Add screenshots with your code and let's see it running and working pls


Not everyone have Jupiter installed to run your python code to check if it's correct.
I was under the impression that volunteer testers would use an online interpreter like pythontutor/jdoodle e.t.c. to run the testcases, I don't even use Jupiter myself. I don't think screenshots are good enough for judging. I can still send you them if you want tho.
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 10:29am On Dec 22, 2022
The approach is;
pick the node with the max sv value, either white or black, and then distribute value (by substracting from the sv) to the smallest nodes of the opposite color untill sv becomes zero or the smallest opposite color node is bigger, then repeat with the next max sv node, nodes visited are not reused. this should work for valid inputs
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 10:22am On Dec 22, 2022
replace nodes with either nodes_test or nodes_test2 in
res = solve(nodes)
to test with the sample data.
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 10:16am On Dec 22, 2022

class Node:
def __init__(self, id, col, val):
self.id = id
self.color = col
self.value = val

def __str__(self):
return f"id: {self.id}, color: {self.color}, value: {self.value}"


class Result:
def __init__(self, n1, n2, w):
self.startnode = n1
self.endnode = n2
self.weight = w

def __str__(self):
return f"sn: {self.startnode.id}, en: {self.endnode.id}, weight: {self.weight}"


def read_inputs():
n = int(input())
res = set()
for i in range(1, n + 1):
s = input().split()
res.add(Node(i, int(s[0]), int(s[1])))
return res

def solve(nodes):
res = []
while len(nodes) != 0:
maxn = max(nodes, key=lambda v: v.value)
# check stray nodes
if maxn.value == 0:
resolve_res = [next_valid_node(maxn, res)]
else:
resolve_res = resolve_edges(maxn, nodes)
nodes.remove(maxn)
res.extend(resolve_res)
return res

def resolve_edges(maxn, nodes):
res = []
while True:
minn = pick_min(maxn, nodes)
if minn is None:
break
if maxn.value >= minn.value:
res.append(Result(maxn, minn, minn.value))
maxn.value -= minn.value
nodes.remove(minn)
else:
res.append(Result(maxn, minn, maxn.value))
minn.value -= maxn.value
nodes.add(maxn)
break
return res

def pick_min(maxn, nodes):
minn = Node(-1, -1, 999)
for node in nodes:
# check colors, reject same color nodes
if node.color == maxn.color:
continue
if node.value < minn.value:
minn = node
return minn if minn.value != 999 else None

def next_valid_node(strayn, nodes):
straycol = strayn.color
for node in nodes:
startcol, endcol = node.startnode.color, node.endnode.color
if startcol != straycol:
return Result(strayn, node.startnode, strayn.value)
if endcol != straycol:
return Result(strayn, node.startnode, strayn.value)

def main():
nodes = read_inputs()
nodes_test = {
Node(1,1,0),Node(2,0,3),Node(3,1,8 ),
Node(4,0,2),Node(5,0,3),Node(6,0,0)
}
nodes_test2 = {
Node(1,1,3),Node(2,1,2),Node(3,0,5)
}
res = solve(nodes)
[print(r.startnode.id, r.endnode.id, r.weight) for r in res]

if __name__ == "__main__":
main()
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 9:19am On Dec 22, 2022
much harder than I imagined, I've been able to come up with a solution though, let me clean it up.
hopefully it passes all test cases
ProgrammingRe: Can You Solve This Google Coding Interview Problem? (pics) by namikaze: 4:18pm On Dec 21, 2022
@sqlPAIN
I haven't been online for the past few days and I usually don't even check the programming section because it's usually dry. I'll try solving this today
SportsRe: Argentina Vs Croatia: FIFA World Cup Qatar2022. Semi-Finals (3 - 0) On 13-12-22 by namikaze: 6:12am On Dec 14, 2022
I pray make morocco win sha, it would be much easier to penetrate morocco's defense than defend against mbappe/giroud.
SportsRe: Argentina Vs Croatia: FIFA World Cup Qatar2022. Semi-Finals (3 - 0) On 13-12-22 by namikaze: 8:01pm On Dec 13, 2022
live streaming link please
ProgrammingRe: What Is Your Your Favorite Programming Language And Why? by namikaze: 1:03am On Nov 12, 2022
TastyFriedPussy:
My favourite programming language is C++, why?

Because it is like the rinnegan of the programming world( those who are naruto fans && programmers would understand).....

Gawd my imagination is fûcked up grin
lol rinnegan is outdated, jougan is the new kid on the block
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 8:10am On Nov 11, 2022
Najdorf:
Abeg no bring this kind question again tongue
Let us just stick to the WordPress wey everyone go sabi
lol, I hear you.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 9:37am On Nov 08, 2022
CyberHustle:
I am still waiting for the three parts you talked about. The is a useless question if sorting will automatically break down a list into three parts.
sigh just forget it.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 7:35pm On Nov 06, 2022
CodingSoft:
I cannot find any use of this coding test on Amazon shopping site. Their site only has these types of sorting: Price: Low to high, Price High to low, Avg. Customer review and Newest arrivals. None of these requires this type of coding test. All that is needed for these are to use the sorting provided by the programming language to achieve these basic kinds of sorting.

This kind of coding test is only useful when it comes to games programming as you'll have to store data in arrays and manually check and retrieve them using the quickest logic possible.

It is not possible to accomplish this coding test in O(1) as you cannot accomplish this task without a nested loop.

O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.

bool IsFirstElementNull(IList<string> elements)
{
return elements[0] == null; //Source: https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/
}
1. loop nesting does not affect space complexity by it self.
2. Time and space are measured differently, there is no "time or space", there's only "time and space"
3. O(1) for time differs from the O(1) for space.
4. The problem is solvable in O(n) time, not O(1).
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 7:57pm On Nov 05, 2022
CyberHustle:
If I reply you the way I ought to, this thread will derail.
Your own question say we need three new lists. But your solution shows only one list and therefore is incomplete. What you have there is a human readable solution and not a computer readable one.

Lastly, any moniker accepting your clearly incomplete solution is your alternate.
Three parts! not three lists, you just don't understand the problem, admit it.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 9:22am On Nov 04, 2022
Deicide:
Space is cheap grin
Not until you have 5 billion records to process.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 9:21am On Nov 04, 2022
Najdorf:
We have explained this thing multiple times in different ways...
I'm even tired sef grin
I dey tell you, he really should look at it from a different perspective.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 6:26pm On Nov 03, 2022
Deicide:
Using extra space would have made it easy. Cause then you can use 3 for loops but the space complexity would be o(n). It would look something like this
This is correct, but space to beat is O(1), which is actually the tricky part.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 6:24pm On Nov 03, 2022
CyberHustle:
If sorting alone is a valid solution then your question is senseless and pointless. Sounds a lot like you looking for clout.

If I need the values less than, equals to, and greater than X, I just loop through and pick the values if it matches my interest. To have three different list within a list. You must know where the less than X values end and note that index in a variable(x_starts for example) then know where greater than X starts(x_ends) in another variable. Any value between is X.
Calm down, you're the only saying the question is pointless, it justs means you probably don't understand it yet.
Think of it as quicksort's partitioning algorithm, every item smaller than or equal to the pivot goes left of the pivot, greater than or equal goes to right.
for example;
piv = 5, arr = [2,5,1,4,7,3,6]
some valid solutions include:
1. [2,4,3,1,5,7,6].
2. [1,2,3,4,5,6,7].
note that 2 is just the array sorted.

The same goes for the question but with the new constraint that all items equal to the pivot stays at the middle, together with the pivot.
for example;
piv = 5, arr = [5,2,5,1,4,5,7,3,6]
some valid solutions include:
1. [2,4,3,1,5,5,5,7,6].
2. [1,2,3,4,5,5,5,6,7].
note that 2 is also just the array sorted.
sigh.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 1:16am On Nov 03, 2022
CyberHustle:
Please compare the challenge and your solution. Where are the three parts of the original list? That's is less than X, X, and greater than X?
The three parts should be in the original list, i.e lower than x the first section, equal to x next and greater than x last.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 8:24pm On Nov 01, 2022
CyberHustle:
How will sorting alone help identify array values lesser, equal to and greater than X?

My solution involves sorting it and then looping thru to identify where values lesser than, equal to and greater then X either end or start. If you are implementing the sort algorithm, you could combine both processes otherwise depend on language shipped sorting function then loop thru to know indexes of interests.
given x = 10 and lst = [9, 12, 3, 5, 14, 10, 10],
sorting lst would yield: [3, 5, 9, 10, 10, 12, 14].
This satisfies the constraints, no need for further processing.
ProgrammingRe: Solve This Amazon Interview Question by namikaze(op): 6:37pm On Nov 01, 2022
CyberHustle:
loop thru d array, and note the index where X is greater than the value(s) stops and the index where X is less than the value(s) start.
You did not get my point, "return sorted(arr)" is automatically a valid solution, no need to loop through anything.

1 2 3 4 5 6 7 (of 7 pages)