GO AHEAD user AND POST YOUR SHITTY SOLUTION

GO AHEAD user AND POST YOUR SHITTY SOLUTION

Other urls found in this thread:

stackoverflow.com/questions/8228758/what-is-the-meaning-of-o1-on-onn-memory#8229063
ArrayDuplicateFinderService.com/').then(res
myredditvideos.com/
twitter.com/SFWRedditImages

nope not again

>You can only use O(1) memory.
1TB is still a constant lol.

for i in list:
for x in list:
if x == i:
return x

Do your own homework/project assignment on your own, Rajajesh

Fuck of Panjeet, it's 4 LOC in C god dammit.

>you must use O(1)
>fucks it up instantly
Here's how you spot the pajeet

just slap something on at the end that makes the computer rest for 1 year. it'll essentially be O(1) then

LOG^@WRONG

Quicksort and then iterate through the array with a counter.

Theta(n) time and O(1) space for an in place sort

def dupe_elem(lst):
for elem in lst:
if elem in lst:
return elem

>repeating this shitty thread so soon after

no

list = [1,2,3,4]

1
does list contain 1?
yes

I meant Theta(nlogn) or O(n2) :V)

I don't think O(1) is quite possible in this case

return list[0]

it'll work sometimes.

Inplace sort and then arr[i]==arr[i+1]

>sorting via any method
>O(1)

Can't be done. If I can only use 1 int of memory, where do I hold the N int array?

I win without writing a single line of code. I'm number 1 coder.

That's not O(1)

O(1) memory, not time.

Post says O(1) memory, doesn't say anything about the time.

This uses O(1) memory, which is fine.

O(1) = constant avg. memory

there you go nigguru

return array.sort().reduce((a,v) => a=[v,(a[0]==v)?a[0]:a[1]] ,[null, null])


now go to bed nigguru

>return array.sort().reduce((a,v) => a=[v,(a[0]==v)?a[0]:a[1]] ,[null, null])

appologies nigguru I made a mistake nigguru

but there you go nigguru

return array.sort().reduce((a,v) => a=[v,(a[0]==v)?a[0]:a[1]] ,[null, null])[1]

If that is the case, the the spec is wrong. The argument cannot be N integers, or it will be O(N)

"o(n) constitutes a linear memory usage. So more input means linearly more memory."

stackoverflow.com/questions/8228758/what-is-the-meaning-of-o1-on-onn-memory#8229063

I still win, 0 lines of code. Number 1 coder.

>constant memory for an array of n elements
what did xir mean by this?

If the same space is used for input and output and the extra memory used by the algorithm is constant]

t.brainlet

ok that's what i thought, thanks lads

Someone is sad
He doesn't know how to write spec
So he blames top #1 programmer

war

...

You're still assuming the input is automatically allocated space in the memory

Guys, O(1) just means the memory needed to produce the output does not grow with the input size (aka is constant). O(n) would mean that the memory needed to produce the output would grow linearly relative to the input size.

This is a valid solution. The memory required to find x is constant and does not grow relative to the length of list.

function getDup(arr) {
return arr.filter((v, k, arr) => arr.indexOf(v) !== k)[0];
}

so then just allocate enough memory to read in and compare 2 variables plus the overhead for remembering where you are in the array. still constant for any size external array.

How does that change the fact that the algorithm doesn't use any ADDITIONAL memory outside of initially allocating space for the input array?

not him but storing n elements naturally takes O(n) space.

so try doing it by reading in only a constant amount of data from an external source

Counter(list).most_common()[0]

>all these niggers reading O(1) and then assuming time complexity
This is why we get a bad rap, because half of you guys couldn't pass 4th grade reading.

>returns the first element
You failed the test.

think about it like this:

you have 1MB of memory in your computer. Find the duplicate element in a 10MB array stored in an external file.

for (int i = 0; i < size; ++i)
{
for (int j = i + 1; j < size; ++j)
if (list[i] == list[j]) return list[i];
}
return -1;

def findDuplicate(nums):
nums = sorted(nums)
for i in xrange(1, len(nums)):
if nums[i] == nums[i - 1]:
return nums[i]

SHUT THE FUCK UP YOU IDIOTS, YOU DON'T KNOW WHAT O(1) MEANS

This person knows

Obviously another #1 programmer like me.

explain how doesn't use O(1) memory

uses (2N+2)*4 bytes memory

try reading the thread

IT DOES

STFU

rip sides

qsort
iterate, comparing adjacent elements
No memory allocation at all.

So you take "O(1) memory" to include the input itself? That's retarded. If you wanted to you could apply the same exact algorithm using two file readers with constant buffer sizes with the input stored in an external file, but I really doubt this is what your homework or your interviewer meant when they said to do it in O(1) space

>le O(1) meme
Create an array of INT_MAX size
Use input values as indices to increment values of the array
Stop when one value reaches 2

def duplicateCheck(lst):
while lst:
x = lst.pop(0)
if x in lst:
return x

int checkmate_op(int array[], int duplicate_element) {
return duplicate_element;
}

import dupefinder
dupefinder.finddupe(mylist)

Complexity in memory denote the size of the work tape needed by your turing machine

Qsort use memory.
Code monkeys talking about complexity theory

This works

OP here, thanks for doing my homework fags.

SET = set()
SET = LIST


There, no more duplicates. Pythonlets BTFO

>constant amount of memory
where the fuck am I going to put the array, then? The array has N integers, what if N is a lot? what if the array can't fit into my fixed amount of memory?

16GB of RAM can store like 16 billion integers

>too dumb to understand the task

Eh, doesnt this just return the first element of the list?

Good catch, surprised it took this long for someone to notice

Use a generator and yield, that fixes the problem

Not true. I'm the OP, I just submitted my homework. Thanks Sup Forums see ya next week!

def t(n):
for i in range(0, len(n)):
sublist = n[0:i] + n[i+1:len(n)]
for k in sublist:
if n[i] == k:
return k

>10/06/17

you think the screencrap will trick someone into spoon feeding you?

vector - vector.uniq

BIRDMIN NO

PM'd you

Request = require('request')
Request.request(JSON.stringify(array), 'ArrayDuplicateFinderService.com/').then(res => {
return res
}, rej => {
return rej
})