You have a array of values

Luis Gonzalez
Luis Gonzalez

You have a array of values:
[0,9,5,13,3,11,7,15,2,10,6,14,3,12,8,17]
You have to get the longest sorted chain possible by only deleting elements.
The solution for above array is:
[0,3,7,10,12,17]
Can you do it?

Attached: smug-girl.png (821 KB, 1330x1080)

Carter Turner
Carter Turner

hard way
Can you do it without using graphs?

Nicholas Brooks
Nicholas Brooks

Do your own homework, kiddo

Lucas White
Lucas White

to be honest i am idiot and i can't even solve this fucking stupid shit for job interview.
I know that i have to use graph as i did in cs, but for love of everything i don't know how to use it in javascript.
What the fuck graphs have to do with node js?

Kevin Brooks
Kevin Brooks

What the fuck graphs have to do with node js
what you mean?, if you can't represent data structures on any programming language find another profession, CS isn't for you.

Carson Fisher
Carson Fisher

Maybe with a directed graph? Direction is, for every element, always from lower to higher value. Then you can select the longest one.

Please correct me and stuff.

Daniel Stewart
Daniel Stewart

What do you mean by longest sorted chain? How is it the solution you put?

Jose Johnson
Jose Johnson

Kinda easy using trees tbqh
Start with 0 as root, for each node create a child for each number that's subsequent AND greater than current node, iterate until tree is complete and then take the longest branch.

Joshua Scott
Joshua Scott

You have to sort value from lowest to highest only by removing elements.
If you have something like this:
1,5,3,6,2,7,3,4,
you will get
1,2,3,4

thanks i will look into this, but i was more thinking about binary search tree

Attached: bst.png (8 KB, 550x300)

Ryan Lee
Ryan Lee

Have fun with that O(n^2) algorithm. Don't worry, we'll call you back.

The solution runs in n log n

Kevin Nelson
Kevin Nelson

building a binary tree is O(n^2)
shred your degree go back to school

Blake Ward
Blake Ward

What you (?) described isn't a binary tree. Each node in a binary tree can have 2 children. Your algorithm allows n children per node

Hunter Gutierrez
Hunter Gutierrez

i'm not the guy who posted the solution, but i see. sorry, i guess i must have misread.

Landon Russell
Landon Russell

If you have something like this:
1,5,3,6,2,7,3,4,
you will get
1,2,3,4
So how can OP's output be that?

Adam Rivera
Adam Rivera

Interesting challenge

Tyler Garcia
Tyler Garcia

I got that Python solution:

def LOS(seq, best = [], i = 0):
if i < len(seq):
if best == [] or best[-1] <= seq[i]:
_with = LOS(seq, best + [seq[i]], i + 1)
_without = LOS(seq, best, i + 1)
if len(_with) > len(_without):
return _with
else:
return _without
else:
return LOS(seq, best, i + 1)
else:
return best

It uses backtrack strategy to find the best combination. I will try to optimize it with dynamic programming.

Julian Ross
Julian Ross

Shit, I've lost the identation u.U

Juan Wood
Juan Wood

[0, 3, 7, 10, 14, 17] also seems to be a valid solution

Ian Sanders
Ian Sanders

python is a shit, who was the retard who tough was ok to include indentation as part of the language?

Robert Russell
Robert Russell

lol pytards its retard if this happened to an small code like this, I can imagine what would happen to a large project without subversion.

Nicholas King
Nicholas King

It's almost as if most text editor maintain spacing and its just Sup Forums that removes it?

Owen Ward
Owen Ward

1 There is the code tag
2 Using tabs for indent its very newfag


def aFagget(input):
print(input + "a fagget")

aFagget("you are")

Kevin Price
Kevin Price

Do you even PEP 8 nigga

Gavin Carter
Gavin Carter

I don't give a fuck about python bullshit its a toy glue language which shouldn't even take seriously.

Zachary Allen
Zachary Allen

If arr[i] > arr[i+1] remove arr[i] from array, - - I, iterate over the array

Colton Wright
Colton Wright

Can't you just recursively compare the last value to the second to last value and delete the last value if it's smaller than the second to last value?
I just started learning how to program a week ago, please don't bully
I feel like most of the things I'm making are already part of standard libraries. I've been reading the gnu c manual and the gnu c library reference manual. Is there any other way to get good and make good code?

Juan Cooper
Juan Cooper

Shit. I just realized if an interviewer asked me this I'd be fucked. Will come back soon with an answer to unfuck myself. Won't look up the answer online.

Cameron Powell
Cameron Powell


What language do you like and why?

Juan Price
Juan Price

concurrent prolog
easy to implement a prolog machine
works as a database with inference support
problems can be solve in an elegant way using only backtracking and unification
very few concepts to learn
you can implement larget REST services in a modular a clean way.
modern computers would be using native prolog instead of assembler if fifth generation computers were not cucked by muricas.

In resume prolog is the best programming language in the whole existence of programming languages.

Disable AdBlock to view this page

Disable AdBlock to view this page

Confirm your age

This website may contain content of an adult nature. If you are under the age of 18, if such content offends you or if it is illegal to view such content in your community, please EXIT.

Enter Exit

About Privacy

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. We also share information about your use of our site with our advertising and analytics partners.

Accept Exit