Coding Interview

Can someone give me some coding interview questions? I wanna see how fucked I'd be, if fucked at all. Falcon tripfag seemed pretty useful, thread died before I could respond to any of his things though.

Attached: LaaaEEEE_DEEJJJ.png (644x688, 16K)

Other urls found in this thread:

pastebin.com/KbqHEK9A
pastebin.com/pE1ZKfrC
twitter.com/NSFWRedditVideo

Write an algorithm for ...
Solve a solution using psuedocode for some problem.

write a code that detects whether or not someone is a tranny

>write a code that detects whether or not someone is a tranny
print "trans-sexuality is a mental illness"
sleep 3600
print "evaluation: sane"

the program assumes that a tranny would attack the computer before the program finishes

>write a code that detects whether or not someone is a tranny

#include

int main() {
struct person{
bool tits = false;
bool dick = false;
} ex_person;

if((ex_person.tits && ex_person.dick))
std::cout

Given a list of numbers, and an integer N, find (if present) a pair of these numbers that sum to N.

Invert a binary tree

Attached: 1519765111084.jpg (690x460, 62K)

>a tranny would attack the computer before the program finishes
You mean, the garbage collector would kick in, you mysogenist trumpftard.

you dun good son

I feel like this is way longer than it should be.

#include
#include

//Because std:: is annoying
using namespace std;

int main ()
{
int arraySize;
int sumValue;
bool foundPair = false;
int numPair[2];

cout > arraySize;
cout > sumValue;

cout

That's more or less the right idea for O(n^2) runtime. Can you do it in less?

Also, to cut down on lines, just use fucking Python or something

def sum_thing(ary, n)
ary.product(ary).detect { |(a,b)| a + b == n }
end


C++ gives me a bad gut feeling

put list of numbers in set S go through list of numbers, and check if (N - number) is in S. Voilá, O(n).

>(N - number) is in S
that seems like O(n^2) time because you go through the set for each number in the list

you don't "go" through a set, you look the hash up, and that's O(1)

you didn't mention any hash set, and what about consideration for the time to put the list into the set?

>you didn't mention any hash set,
My bad, but I think that was implied, unless you want an ordered set (then you would use treeset).
>and what about consideration for the time to put the list into the set?
Iterating through the list is O(n), and adding the items to the set is O(1).

So, unless I am missing something, creating the set is O(n), and going though the list to check if N-n is in it is O(n) as well, so the whole thing is O(n).

Thanks for the explanation

Attached: 1515169474012.jpg (1280x1280, 262K)

>write a code that detects whether or not someone is a tranny
bool thereAreOnlyTwoGenders = true;
do {
yourselfAFavor();
} while (thereAreOnlyTwoGenders);

Thank you for your application, we'll be in touch :^)

>randArray[i] = rand()%10+1;

rand() is bad; using modulo for ranges is bad too.

> int randArray[arraySize];

VLAs don't exist.

>declaring all the variables at the top of the function

Stop coding like it's the 80s.

pastebin.com/KbqHEK9A

O(n*log(n)) time

Also if you wanted i=/=j for the pair of elements then:
pastebin.com/pE1ZKfrC

scream FIZZBUZZ loudly 100 times without looping

System.out.println("FIZZBUZZ");

just copy and paste that 99 more times

#include

void fizzbuzz(int x){
if(x){
std::cout

>java

pajeet my poo

Is that python?

Write a Linked List.
First the data structure.
Then functions, insert, delete and reverse list.

That's the coding question I received when I got an internship at Cisco (northern Europe).

>Can someone give me some coding interview questions?
I was asked this one by Google.

You have a staircase with N steps. In one move, you can climb either one step or two steps. How many different ways can you climb the stairs with N steps? Write a function that calculates this.

Write a code that prints out the current time.

System.out.println("the current time");

A simple recursive function that called itself with +1 and +2 steps until it hits N. Add +1 to a static variable each time the function is called.
Will use a lot of time though.

>A simple recursive function that called itself with +1 and +2 steps until it hits N.
In other words? (Protip: what sequence is this?)

>Add +1 to a static variable each time the function is called.
Not needed.

def climb(steps):
if steps == 1:
return 1 # There's only one way to climb a one step stair
if steps == 2:
return 2 # You can climb it in two ways (either one double step or two single steps)

return climb(steps - 1) + climb(steps - 2)

Write a program that determines whether another binary ever goes into an infinite loop.

And then give the program itself as input to your progam, right?


>pls solve the halting problem for us

>What sequence
Idk?
Actually you can just multiply the amount of steps you have so far by two each time and only call the function with +2 steps until you have taken N steps. Will run in logN time.
Also needs an if check to see if you need to take 1 step as the last step.

See

def recursive(steps, cnt)
if steps == 1
return cnt + 1
else if steps == 2
return cnt*2
return recursive(steps - 2, cnt*2)


Will this work? I am a bit unsure, but at least it will run fast.

I tried to do it in a modernish way, the only thing I'm not proud of here is the throw, but due to shitty C++'s support of std::optonal I guess its the best way.
#include
#include
#include
#include
#include
#include

std::pair find_terms(int sum, std::vector const &numbers)
{
std::pair result;
for(unsigned it1 = 0; it1 < numbers.size(); ++it1)
{
for(unsigned it2 = 0; it2 < numbers.size(); ++it2)
{
if(it1 == it2) ++it2;
if(numbers[it1] + numbers[it2] == sum)
{
result.first = numbers[it1];
result.second = numbers[it2];
return result;
}
}
}
throw std::logic_error("no terms found");
}

int main()
{
std::srand(std::time(NULL));
std::vector numbers;
int sum = std::rand() % 20;
for(unsigned it = 0, size = std::rand() % 100; it < size; ++it)
{
numbers.push_back(std::rand() % 10);
}
std::pair result;
try
{
result = find_terms(sum, numbers);
}
catch(std::exception &e)
{
std::cout

> not:
std::cout

>Will this work? I am a bit unsure, but at least it will run fast.
Does it produce the Fibonacci sequence?

A really common one that is asked frequently during the technical communication part of your interview.

"tell me about a project you worked on"

...