Interesting task for programmers

D
Site user since 18.12.2015
Offline
142
#41

hakuna matata, the Go Easy is written, I had 100k and green of threads shlyuschih somewhere data.

Разработка и поддержка высоконагруженных проектов.
HM
Site user since 14.01.2012
Offline
208
#42

Danforth, Easy if you are coder, but I'm not. Recommend something to read?

I have a level of zero, send a lot of requests I can even likely, but process them asynchronously - not sure. How to do it right?

D
Site user since 18.12.2015
Offline
142
#43

hakuna matata, Go tour.

There is another very legenky task, but which can be defined as the person is able to optimize the code:

There is a list of numbers, for example [3, 2, 4], and the target number 6. It is necessary to return the indices of the array, the sum of which is equal to the target number. If as a result there are some combinations should be returned first.

For example, [3, 2, 4] and the target number of 6.

2 + 4 = 6, y 2 Index 1 and Index 2 y 4, return the array indices [1, 2].

For example, [1, -4, 6, 9, 4, 3, 8], and the target number 5.

5 = -4 + 9, y -4 index 1 and index 3 in 9, return [1, 3]

The signature function takes an array of numbers, and the target number, it returns an array of numbers (two elements of the array length):


class Solution:
def twoSum (self, nums: List [int], target: int) -> List [int]:


class Solution {

/ **
* @Param Integer [] $ nums
* @Param Integer $ target
* @Return Integer []
* /
function twoSum ($ nums, $ target) {

}
}

Solutions throw right here, it is desirable to link to pastebin, so as not to scorch spoilers with solutions.

I got two implementations, the first written "in a dull", the second - optimized.

tommy-gung
Site user since 22.11.2006
Offline
258
#44

https://pastebin.com/Fs9kNa4J let too will lie down

Здесь не могла быть ваша реклама
D
Site user since 18.12.2015
Offline
142
#45

tommy-gung, a working solution, but it is possible to optimize) the first implementation I have also worked well, this is the first that comes to mind.

S3
Site user since 29.03.2012
Offline
212
#46

To find the first pair of indices:

https://pastebin.com/3zZ45mts

Return I was little changed accordingly tayphinty in the condition corrected, too, think this is not essential, but clearer

D
Site user since 18.12.2015
Offline
142
#47

Sly32, you changed the signature, if we change the signature in the problem (and the types of arguments in the function must be the same, no tuples), I can drive your function and benchmark tests.

Do you make the same decision as that tommy-gung, but it can be improved, if you think about how.

S3
Site user since 29.03.2012
Offline
212
#48

Danforth, so right?

https://pastebin.com/3zZ45mts

Nawal work Wait, so this is the first solution that came to mind, and it is far from optimal, understand, and if you look for all the indices for the number - get doubles - This shows that neoptimal can play more later

D
Site user since 18.12.2015
Offline
142
#49
Sly32:
Danforth, so right?
https://pastebin.com/3zZ45mts
Nawal work Wait, so this is the first solution that came to mind, and it is far from optimal, understand, and if you look for all the indices for the number - get doubles - This shows that neoptimal can play more later

In your function has no arguments, it takes them out of the object. Here's the code that I threw for python, you need to write code in a function, without self

Gerga
Site user since 02.08.2015
Offline
89
#50
Danforth:
Solutions throw right here, it is desirable to link to pastebin, so as not to scorch spoilers with solutions.
I got two implementations, the first written "in a dull", the second - optimized.

EXAMPLE implementation on php https://pastebin.com/xxQ1TZ10

To post a new comment, please log in or register