Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,238 members, 7,953,889 topics. Date: Friday, 20 September 2024 at 08:24 AM |
Nairaland Forum / Science/Technology / Programming / Algorithm And Data Structure Study Section (7595 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 LikeAking: 9:50pm On Jan 05, 2023 |
truthCoder2:Can u xplain the question for me? |
Re: Algorithm And Data Structure Study Section by Nobody: 10:07pm On Jan 05, 2023 |
LikeAking: Yet to see your contribution. |
Re: Algorithm And Data Structure Study Section by LikeAking: 10:19pm On Jan 05, 2023 |
GREATIGBOMAN: Dey wait. |
Re: Algorithm And Data Structure Study Section by Nobody: 4:07am On Jan 06, 2023 |
namikaze: Let me try. 1 Like |
Re: Algorithm And Data Structure Study Section by Nobody: 4:20am On Jan 06, 2023 |
namikaze: function consecNumbers(input) { var output = []; var str = ""; for (var i = 0; i < input.length; i++) { if (input[i] - input[i + 1] === -1 || input[i] - input[i + 1] === 0) { str = str + input[i]; } else { str = `${str.charAt(0) + "->" + input[i]}`; if (str.substring(0, 2) === "->" ) { output.push(`${input[i]}->${input[i]}`); } else { output.push(str); } str = ""; } } console.log(output); return output; } consecNumbers([0, 1, 2, 5, 7, 8, 9, 9, 9, 9, 10, 11, 15]); https://www.jdoodle.com/a/5Hm0 1 Like
|
Re: Algorithm And Data Structure Study Section by Nobody: 4:30am On Jan 06, 2023 |
truthCoder2: wrong as usual. Your Gf ChatGpt have failed u once again
|
Re: Algorithm And Data Structure Study Section by Nobody: 4:55am On Jan 06, 2023 |
namikaze: function consecNumbers(input) { var output = []; //////// With comments. var str = ""; //Empty string to join values that pass a specific test for (var i = 0; i < input.length; i++) { // Looping the sorted array. if (input[i] - input[i + 1] === -1 || input[i] - input[i + 1] === 0) { //Since the array is already sorted, if the current value in the loop minus the next //value ===-1 then we know we've gotten a consecutive match //If the current value minus the next value ===0 then we know they are identical (Also works for negaTive numbers) str = str + input[i]; // If the first test passes join the string the values } else { //Else now we know we've reached the break point were our first test is no longer true //that is, current value - next !=== -1 or 0 str = `${str.charAt(0) + "->" + input[i]}`; // since we've stored the first test in varibale "str" // per the question, we need only the start to the end of each consecutive number //so we grab the first consec number we saved in the first test and add it to the break point if (str.substring(0, 2) == "->" ) { //But if the stored value doesn't have any consecutive sibling, we know the first 2 elements in the string will be "->" as per what is use as an arrow or whatever in the question. output.push(`${input[i]}->${input[i]}`); // We just grab that single runaway element and make it mattch the flow of the question, then push it into the output array } else { output.push(str); // else we know it has consecutive siblings also push it to the output array. } str = ""; //Now we reset our "str variable for the next round of test" } } console.log(output); return output; //return || print } consecNumbers([0, 1, 2, 5, 7, 8, 9, 9, 9, 9, 10, 11, 15]); 1 Like |
Re: Algorithm And Data Structure Study Section by Nobody: 7:31am On Jan 06, 2023 |
namikaze: You never mentioned this should be a sorted array |
Re: Algorithm And Data Structure Study Section by namikaze: 9:58am On Jan 06, 2023 |
Re: Algorithm And Data Structure Study Section by namikaze: 10:00am On Jan 06, 2023 |
GREATIGBOMAN:no it's not sorted |
Re: Algorithm And Data Structure Study Section by truthCoder: 10:00am On Jan 06, 2023 |
GREATIGBOMAN: Very dumb of you to say my response was wrong. The only omission i made was not formatting the string to repeat if start === end. You still dey get mouth in this arena? You should be thanking your stars that the mods saved your tiny html ass. LOL.
|
Re: Algorithm And Data Structure Study Section by Nobody: 12:24pm On Jan 06, 2023 |
truthCoder: Small small u go get sense. |
Re: Algorithm And Data Structure Study Section by truthCoder2: 12:55pm On Jan 06, 2023 |
GREATIGBOMAN: says the empty nothing who needs to call himself great. How far? You finally converted your infected site to a honeypot abi? You want to harvest people's LinkedIn details? No one really visits your site before. You for put the site online back make i try the other vulnerabilities i didnt discuss here. Your LiteSpeed account is wasting o.. And oh...the mail scripts you are sending to my mails and your feeble attempts through your other monikers. . Wannabe Programmer Oshi
|
Re: Algorithm And Data Structure Study Section by Nobody: 1:00pm On Jan 06, 2023 |
truthCoder2: The thing really pain you. Little by little you'll be able to solve basic Algorithms without ChatGPT. 301 redirect is now rocket science to you. 1 Like |
Re: Algorithm And Data Structure Study Section by truthCoder: 1:26pm On Jan 06, 2023 |
GREATIGBOMAN: Your complete website has now turned to a honeypot to harvest LinkedIn profiles and you call yourself a developer? I didn’t need chatGPT to bring down your website with effects up till today. Now you dont have a functioning website. Oga programmer whose website has been down since Christmas. You are so engulfed with hate that you turned your whole website into a redirect to your LinkedIn profile. You are also so incompetent that you could not fix your vulnerabilities in over 2 weeks. Yet you are as opinionated as a perfumed donkey. |
Re: Algorithm And Data Structure Study Section by Nobody: 1:34pm On Jan 06, 2023 |
truthCoder: Na me get website. Na me use my hand redirect my website to my LinkedIn profile. Yet you're wailing up and down You that have a functioning portfolio site can we see it? |
Re: Algorithm And Data Structure Study Section by truthCoder: 1:39pm On Jan 06, 2023 |
GREATIGBOMAN: LOL. I have a functional portfolio. You have tried all the skills in your skull to get an access but nah. Not for you. You even used your little yahoo yahoo email scripts on my disposable emails but nah. You are too micro. I know one of these days, i will have you at the other side of the table where you would be explaining how good you are with react. LOL As I always tell you, dont rush. 1 Like |
Re: Algorithm And Data Structure Study Section by Nobody: 1:41pm On Jan 06, 2023 |
truthCoder: You have been heard. Shift... |
Re: Algorithm And Data Structure Study Section by truthCoder: 1:43pm On Jan 06, 2023 |
GREATIGBOMAN: Redacted |
Re: Algorithm And Data Structure Study Section by Nobody: 1:51pm On Jan 06, 2023 |
truthCoder:Take your own advice. No one is bigger than a rejection in any Job application. When you're done you can go back to stalking my portfolio website.... We know things are hard these days and Jobs are hard to come by. With enough pleading I may remove the redirect so you can masturbate on the website once again. |
Re: Algorithm And Data Structure Study Section by Ajibade123(m): 5:31pm On Jan 06, 2023 |
This thread is so inspiring Imagine what it could have been if nairaland was open to new features, we could have a code writing feature where people can write code live while on the site.......especially those guys that are always battling for superiority on this section |
Re: Algorithm And Data Structure Study Section by engrAAS: 12:37pm On Jan 07, 2023 |
namikaze: import sys import math class Node: def __init__(self, value, color, left=None, right=None, parent=None): self.value = value self.color = color self.left = left self.right = right self.parent = parent class RedBlackTree: def __init__(self): self.root = None def insert(self, value): new_node = Node(value, "RED" self.insert_node(new_node) def insert_node(self, new_node): if self.root is None: # the tree is empty, the new node is the root self.root = new_node else: current_node = self.root while True: if new_node.value < current_node.value: # the new node goes in the left subtree if current_node.left is None: # the current node has no left child, the new node becomes its left child current_node.left = new_node new_node.parent = current_node self.rebalance(new_node) break else: # the current node has a left child, we continue the search in the left subtree current_node = current_node.left else: # the new node goes in the right subtree if current_node.right is None: # the current node has no right child, the new node becomes its right child current_node.right = new_node new_node.parent = current_node self.rebalance(new_node) break else: # the current node has a right child, we continue the search in the right subtree current_node = current_node.right def find_node(self, value): current_node = self.root while current_node is not None: if value == current_node.value: # we found the node, return it return current_node elif value < current_node.value: # the value we are looking for is in the left subtree current_node = current_node.left else: # the value we are looking for is in the right subtree current_node = current_node.right # we didn't find the node, return None return None def count(self, node): if node is None: return 0 else: return 1 + self.count(node.left) + self.count(node.right) def find_median(self): # get the total number of nodes in the tree total_count = self.count(self.root) HENCE I USED chatGPT |
Re: Algorithm And Data Structure Study Section by Nobody: 5:09pm On Jan 07, 2023 |
engrAAS: Using ChatGpt is just annoying. You can use it to get insights or how to solve the problem perhaps... But not to solve the entire thing for you and you just copy and paste it. What did you learn now? |
Re: Algorithm And Data Structure Study Section by truthCoder: 5:21pm On Jan 07, 2023 |
GREATIGBOMAN: You had a rethink overnight and edited this post abi? Christmas is over. I am back to normal grind. I wont mind using you to relax once in a while. ..you know, the occasional shafting. You can put your website back. Dont be afraid, i dont bite deep. You should be proud, i am your one and only traffic. Jokes aside, dont take down your site because you were washed with bleach. There were learning points and it should have made you a better programmer. Put it up and I would let you know privately (through one of your numerous emails that i now have) any issue i notice. Cheers sleekcode greatigboman and the two other monikers you have used in contacting me. 1 Like |
Re: Algorithm And Data Structure Study Section by truthCoder: 5:27pm On Jan 07, 2023 |
GREATIGBOMAN: Using chatGPT assists in learning. Don’t fight existing realities. Not everyone has the luxury of time to learn every bit of a process. At least, the person was forthright and declared where the solution came from. If you are not comfortable with his option, then you present yours or move on to other things. You sound like someone from the 80s saying ‘dont use a calculator’ |
Re: Algorithm And Data Structure Study Section by Nobody: 7:12pm On Jan 07, 2023 |
truthCoder: I said it can be used to get insights on how to solve a problem. Which is exactly what it was meant to do... Assist humans in solving problems by providing elucidated context. Pasting problems there and copying the solutions verbatim only shows how lazy you are and doesn't improve your learning in anyway. No point explaining these things to you sha... You're so hooked to this ChatGpt because that's the only way you can provide any correct solution to anything. |
Re: Algorithm And Data Structure Study Section by namikaze: 7:23pm On Jan 07, 2023 |
engrAAS:wrong answer, solved a completely different problem (it implemented a red black tree, which I'm guessing is still buggy). I've tried chatGPT before, it always gives wrong solutions except for the most basic and generic problems, you'd be better of solving a problem from scratch than debugging it's solutions. |
Re: Algorithm And Data Structure Study Section by Nobody: 7:29pm On Jan 07, 2023 |
truthCoder: You need help! You're so addicted to this my website Mr Stalker I've gotten more than 10,000 visits from your smelling IP alone. Are you that jobless? I thought you specialized in selling 10 years old laptops as side hustle....? Why not use that one to hold body before your normal 5k-10k projects comes around. Don't worry yourself sha... Before you choke in your addiction and die from not seeing my wonderful website online. I'll soon bring in back live so you may practice your kindergarten Pen-testing skills and baby hacks. 1 Like |
Re: Algorithm And Data Structure Study Section by Nobody: 8:10pm On Jan 07, 2023 |
namikaze: Javascript. function medianStreams() { var input = [2, 1, 4, 7, 2, 0, 5]; var joiner = []; var output = []; for (let num of input) { joiner.push(num); if (joiner.length === 1) { output.push(joiner[0]); } else { if (joiner.length % 2 === 0) { let evenMiddle = joiner.sort().length / 2; let average = joiner[evenMiddle] + joiner[evenMiddle - 1]; output.push(average/2); } else { let oddMiddle = joiner.sort().length - 1; output.push(joiner[oddMiddle / 2]); } } } console.log(output); return output; } medianStreams(); https://www.jdoodle.com/ia/BWD
|
Re: Algorithm And Data Structure Study Section by engrAAS: 8:52pm On Jan 07, 2023 |
namikaze: Noted, thanks for the correction 1 Like |
Re: Algorithm And Data Structure Study Section by namikaze: 12:58pm On Jan 08, 2023 |
GREATIGBOMAN:fails some test cases, for example, arr = [2,6,10,1,0]; correct answer should be [2,4,6,4,2], yours:
|
Re: Algorithm And Data Structure Study Section by Nobody: 1:04pm On Jan 08, 2023 |
namikaze: Ok |
(1) (2) (3) (4) (5) (6) (7) (Reply)
Reusable Object-oriented Patterns In Banking Applications / Embedded Systems / Were Can I Download Free Video Tutorials On Javascript Or Ruby
(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. 83 |