Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,641 members, 7,816,639 topics. Date: Friday, 03 May 2024 at 02:18 PM

Algorithm And Data Structure Study Section - Programming (5) - Nairaland

Nairaland Forum / Science/Technology / Programming / Algorithm And Data Structure Study Section (6931 Views)

Data Structure And Algorithm With Php / Is It Possible To Learn Algorithm And Data Structures? / Nigerian Developers How Did You Master Algorithm And Problem Solving (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (Reply) (Go Down)

Re: Algorithm And Data Structure Study Section by Nobody: 9:33pm On Jan 11, 2023
qtguru:


Oh I see, let's benchmark it with a high length of array and see what the time difference will be. Can you share a link ?

NOTE: @GREATIGBOMAN, I see devdevdev's point, the constant is n (Length of Array), if there are 5 million items, you will loop 5 million times, that's a brute force, but I don't think it's room for argument, it's an opportunity to provide alternative algo that is efficient.

Let's not argue and look at efficient runtime. I will join you guys soon, this week or next.


She's just trying to get back at me for pointing out her pile of trash on one of her threads.
Re: Algorithm And Data Structure Study Section by qtguru(m): 9:38pm On Jan 11, 2023
GREATIGBOMAN:



She's just trying to get back at me for pointing out her pile of trash on one of her threads.


I don't think it's that, your time complexity is kinda Quadratic, you have 2 loops for an n length of array, O(n^ 2), which will really take a lot of time if the input gets large.
Re: Algorithm And Data Structure Study Section by Nobody: 9:42pm On Jan 11, 2023
qtguru:


I don't think it's that, your time complexity is kinda Quadratic, you have 2 loops for an n length of array, O(n^ 2), which will really take a lot of time if the input gets large.

Ok.

But based on the question asked does that render my solution wrong or inefficient?
Re: Algorithm And Data Structure Study Section by qtguru(m): 9:46pm On Jan 11, 2023
GREATIGBOMAN:


Ok.

But based on the question asked does that render my solution wrong or inefficient?

It depends, most algorithm target efficient and correctness. Brute force at least you know you are right, but as devdevdev mentioned, input gets large overnight, so an efficient algorithm is usually favored.

I don't want you guys to fight, I think the debate between you two is healthy for suggesting faster solutions.

Shalom.

2 Likes

Re: Algorithm And Data Structure Study Section by Devdevdev(f): 9:49pm On Jan 11, 2023
GREATIGBOMAN:


Ok.

But based on the question asked does that render my solution wrong or inefficient?

No interviewer will pass your solution, olodo. It is slow, inefficient and plain lazy for someone claiming to be an experienced programmer.

Imagine implementing your solution on a large data set. It will take your app hours to load. Mine will take milli seconds. If you can't see the difference then you are irredeemably daft.
Re: Algorithm And Data Structure Study Section by Nobody: 9:50pm On Jan 11, 2023
qtguru:


It depends, most algorithm target efficient and correctness. Brute force at least you know you are right, but as devdevdev mentioned, input gets large overnight, so an efficient algorithm is usually favored.

I don't want you guys to fight, I think the debate between you two is healthy for suggesting faster solutions.

Shalom.

grin

I'm not in this thread to fight either.


But all her replies/comments screams of violence and like someone who's been preparing for this moment for a while now.

No point derailing the thread over a depressed Gen X

You can have your moment dev dev dev grin
Re: Algorithm And Data Structure Study Section by Nobody: 9:53pm On Jan 11, 2023
Devdevdev:


No interviewer will pass your slow solution, olodo. It is slow, inefficient and plain lazy for someone claiming to be an experienced programmer.

Imagine implementing your solution on a large data set. It will take your app hours to load. Mine will take milli seconds. If you can't see the difference then you are irredeemably daft.

grin

Welcome to the thread.

Your inspirational comments won't stop me from posting... Just be here to provide you efficient solutions.
Re: Algorithm And Data Structure Study Section by qtguru(m): 9:54pm On Jan 11, 2023
Devdevdev:


No interviewer will pass your slow solution, olodo. It is slow, inefficient and plain lazy for someone claiming to be an experienced programmer.

Imagine implementing your solution on a large data set. It will take your app hours to load. Mine will take milli seconds. If you can't see the difference then you are irredeemably daft.

Please no need for insults we are all learning, else the purpose of this thread will be defeated. cry

1 Like

Re: Algorithm And Data Structure Study Section by Devdevdev(f): 10:04pm On Jan 11, 2023
qtguru:


Please no need for insults we are all learning, else the purpose of this thread will be defeated. cry

The person I "insulted" denigrated me when I asked a simple question two months ago when I was still in the beginning stages of my learning. But now I have improved beyond my expectations and can build complex apps from scratch on my own using vanilla Js and reactJs. I've also been practicing DSAs like a mad woman.

He called me a failure because I had trouble fetching data from an API, but here he is two months later, unable to solve a simple algorithm question. How the tables have turned. He deserves all the insults.

1 Like

Re: Algorithm And Data Structure Study Section by Unclesamo(m): 10:18pm On Jan 11, 2023
Devdevdev:


No interviewer will pass your solution, olodo. It is slow, inefficient and plain lazy for someone claiming to be an experienced programmer.

Imagine implementing your solution on a large data set. It will take your app hours to load. Mine will take milli seconds. If you can't see the difference then you are irredeemably daft.
Re: Algorithm And Data Structure Study Section by Unclesamo(m): 10:20pm On Jan 11, 2023
Devdevdev:


The person I "insulted" denigrated me when I asked a simple question two months ago when I was still in the beginning stages of my learning. But now I have improved beyond my expectations and can build complex apps from scratch on my own using vanilla Js and reactJs. I've also been practicing DSAs like a mad woman.

He called me a failure because I had trouble fetching data from an API, but here he is two months later, unable to solve a simple algorithm question. How the tables have turned. He deserves all the insults.

seriously?
so, you didn't forget that incident also.

lol. I never knew it's even up to 2months.

Biko .. no vex

1 Like

Re: Algorithm And Data Structure Study Section by Nobody: 10:38pm On Jan 11, 2023
namikaze:

with recursive dfs
jdoodle.com/ia/C7K

map = {
'2':"abc",'3':"def",'4':"ghi",
'5':"jkl", '6':"mno",'7':"pqrs",
'8':"tuv",'9':"wxyz"
}

def letterCombinations(s, cur="", res=[]):
if s == "":
res.append(cur)
return

n, s = s[0], s[1:]
for adj in map[n]:
letterCombinations(s, cur+adj, res)

return res


s = "23"
print(letterCombinations(s))

Nice.
Let me try

1 Like

Re: Algorithm And Data Structure Study Section by Nobody: 12:36am On Jan 12, 2023
Sleekcode:
Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.




Example:
Javascript solution

https://jdoodle.com/ia/C7U

nested loops... before you come for my head... they are different methods to solve this question, one of such is using a recursive function.

simply use the one you're most comfortable with.



Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:

Although the above answer is in lexicographical order, your answer could be in any order you want.

Difficulty= Medium
Re: Algorithm And Data Structure Study Section by Nobody: 12:37am On Jan 12, 2023
Sleekcode:
Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.




Example:




Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:

Although the above answer is in lexicographical order, your answer could be in any order you want.

Difficulty= Medium

Javascript solution

https://jdoodle.com/ia/C7U

nested loops... before you come for my head... they are different methods to solve this question, one of such is using a recursive function.

simply use the one you're most comfortable with.
Re: Algorithm And Data Structure Study Section by Nobody: 12:52am On Jan 12, 2023
That one yapping her mouth... your so-called only correct solution even looks suspiciously copied online... Can't be 100% coincidental the naming of your function and some variables are in sync with this solution on StackOverflow.

Whichever copied source/sauce works for you sha... grin

At least you are learning.
Changing some things to make your code appear unique is also part of learning grin

1 Like 1 Share

Re: Algorithm And Data Structure Study Section by sqlPAIN: 6:47am On Jan 12, 2023
Devdevdev:


No interviewer will pass your solution, olodo. It is slow, inefficient and plain lazy for someone claiming to be an experienced programmer.

Imagine implementing your solution on a large data set. It will take your app hours to load. Mine will take milli seconds. If you can't see the difference then you are irredeemably daft.
I'm beginning to love this grin
All of una for this thread dey mad!!! grin
Infact, hunger fire all of una there grin
Re: Algorithm And Data Structure Study Section by AlchemyOfCodes: 11:09am On Jan 12, 2023
Omo thread don turn war-zone. Me wey I just dey reason to post my spaghetti code. Anyway I go still post am sha. Insult no dey kee person grin

1 Like

Re: Algorithm And Data Structure Study Section by Najdorf: 12:01pm On Jan 12, 2023
GREATIGBOMAN:


Ok.

But based on the question asked does that render my solution wrong or inefficient?
The whole point of DSA is solving problems as efficiently as possible
Re: Algorithm And Data Structure Study Section by Nobody: 12:23pm On Jan 12, 2023
Najdorf:

The whole point of DSA is solving problems as efficiently as possible

Understandably... doesn't make a native solution wrong tho.
Re: Algorithm And Data Structure Study Section by Maxxim: 12:31pm On Jan 12, 2023
AlchemyOfCodes:
Omo thread don turn war-zone. Me wey I just dey reason to post my spaghetti code. Anyway I go still post am sha. Insult no dey kee person grin
Post am Bros, all join we all came here to learn ni
Re: Algorithm And Data Structure Study Section by tosinhtml: 12:34pm On Jan 12, 2023
Devdevdev:


You still don't want to accept that your solution is slow and will give you a FAIL in an interview.

Ordinary this simple algorithm question and you can't provide an efficient solution. How will you now solve harder questions efficiently?

Set awon Nairaland troll. Maybe if you invest all the time you use in trolling and insulting people into practicing DSA questions, you'll get better. You are still at level zero. Providing brute force solution to ordinary Two Sum question.

It's clear that all my hard work is paying off. The more knowledgeable I become the more I realize just how much of a quack people like you are. Continue trolling Nairaland from morning till night while I invest my time improving my coding skills.


Why are you hell bent on causing chaos exactly? Your solution is faster, great! Okay you have gotten better, also great! So what's the problem and why do you have to curse out other people contributing to a thread. If you're in an interview, 9 out 10 times you're going to think of the naive solution first before optimising it further. That your code is faster doesn't mean the other person is a quack or useless. So let us enjoy the thread please.

4 Likes

Re: Algorithm And Data Structure Study Section by tosinhtml: 12:36pm On Jan 12, 2023
Najdorf:

The whole point of DSA is solving problems as efficiently as possible

It doesn't make the native solution wrong. In an interview you're most likely not going to write the efficient code the first time, It takes a second trial for most people to improve their code and make it faster. Your job is to focus on solving the problem, before adding efficiency.

3 Likes

Re: Algorithm And Data Structure Study Section by LUAN1: 6:19pm On Jan 12, 2023
Sleekcode:


You don't just suddenly understand everything to the point of solving all the problems.


If you start solving from the very basics, you'd see yourself solving medium difficult questions in few months time
thanks for this
Re: Algorithm And Data Structure Study Section by Nobody: 6:48pm On Jan 12, 2023
Longest Palindromic Substring


Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Input: "babad"
Output: "bab"

Note: "aba" is also a valid answer.

Example 2:

Input: "cbbd"
Output: "bb"

Difficulty:

Medium

2 Likes

Re: Algorithm And Data Structure Study Section by Nobody: 7:09pm On Jan 12, 2023
GREATIGBOMAN:
Longest Palindromic Substring


Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Input: "babad"
Output: "bab"

Note: "aba" is also a valid answer.

Example 2:

Input: "cbbd"
Output: "bb"

Difficulty:

Medium

First solution although correct always exceeding time limit on leetcode when it gets to >=1000 length of string.
Re: Algorithm And Data Structure Study Section by namikaze: 8:05pm On Jan 12, 2023
GREATIGBOMAN:


Javascript solution

https://jdoodle.com/ia/C7U

nested loops... before you come for my head... they are different methods to solve this question, one of such is using a recursive function.

simply use the one you're most comfortable with.
nicee
Re: Algorithm And Data Structure Study Section by sqlPAIN: 8:14pm On Jan 12, 2023
Bunch of women
Re: Algorithm And Data Structure Study Section by Nobody: 2:42am On Jan 13, 2023
GREATIGBOMAN:
Longest Palindromic Substring


Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Input: "babad"
Output: "bab"

Note: "aba" is also a valid answer.

Example 2:

Input: "cbbd"
Output: "bb"

Difficulty:

Medium

Finally got leetcode to accept the answer after 3-4 refactoring. grin

Re: Algorithm And Data Structure Study Section by Devdevdev(f): 3:35am On Jan 13, 2023
Banned like the clown that he is. Spamming this thread with his slow, brute force solutions. Thanks anti-spam bot.

(1) (2) (3) (4) (5) (6) (7) (Reply)

What Softwares Are Used To Push Codes To A Live Website / Machine Learning/data Science/analytics / How To Build A Snakes And Ladders Game With C++ (no Gui)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 49
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.