You have a array of values:

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 (1330x1080, 821K)

>hard way
Can you do it without using graphs?

Do your own homework, kiddo

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?

>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.

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.

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

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.

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 (550x300, 8K)

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

The solution runs in n log n

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

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

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

>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?

Interesting challenge

I got that Python solution:

def LOS(seq, best = [], i = 0):
if i < len(seq):
if best == [] or best[-1] 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.

Shit, I've lost the identation u.U

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

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

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.

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

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

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

aFagget("you are")

Do you even PEP 8 nigga

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

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

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?

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.

What language do you like and why?

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.