Open Side Menu Go to the Top

04-25-2017 , 02:05 PM
Quote:
Originally Posted by Larry Legend
On the subject of interview questions, my friend got a decent one the other day:

Find out if an integer is a palindrome without converting it to a string.

Then part 2 after you answer that:

Spoiler:
Then find out if it is a palindrome without using checking two arrays against each other.
Part 1 uh can't you just split it into an array and do comparison?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
04-25-2017 , 02:09 PM
Quote:
Originally Posted by Larry Legend
On the subject of interview questions, my friend got a decent one the other day:

Find out if an integer is a palindrome without converting it to a string.

Then part 2 after you answer that:

Spoiler:
Then find out if it is a palindrome without using checking two arrays against each other.
Spoiler:
Code:
function reverseNumber(num) {
  let ret = 0;
  while (num > 0) {
    ret *= 10;
    ret += num % 10;
    num = Math.floor(num / 10);
  }
  return ret;
}

function isPalindrome(num) {
  return reverseNumber(num) === num;
}


I hate interview questions like this, seems like it'd be very loosely correlated with whether someone's actually a good programmer or not.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:07 PM
I wouldn't recall the exact equation off my head, but this is how I'd do it....

Spoiler:
Code:
import math

def reverse_int(num):
    if num < 10:
        return num
    else:
        ones = num % 10
        rest = num // 10
        return ones * 10 ** int(math.log10(rest) + 1) + reverse_int(rest)

def is_palindrome(n):
    r_int = reverse_int(n)
    if n == r_int:
        return True
    return False

print(is_palindrome(500))
print(is_palindrome(5005))
print(is_palindrome(5))

>>> False
True
True


With goofy on this one. I hate these kinds of questions.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:13 PM
Quote:
Originally Posted by Grue
Part 1 uh can't you just split it into an array and do comparison?
dont you need to turn it into a string before you can split it into an array?

oh I guess you can mod by 10 for each index.

so
List=digits
while(n>0)
digits.add(n%10)
n=n/10

and now that I start thinking about this, I actually had this question for an interview. I got it right lol. I used to be better at this stuff.

Last edited by Victor; 04-25-2017 at 03:20 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:13 PM
Quote:
Originally Posted by goofyballer
I hate interview questions like this, seems like it'd be very loosely correlated with whether someone's actually a good programmer or not.
Yup. I'm more and more convinced that a screening question like this should have a pretty obvious solution (or better, solutions) and the candidate just has to show that they can take that abstract solution and make it work in code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:14 PM
Quote:
Originally Posted by daveT
I wouldn't recall the exact equation off my head, but this is how I'd do it....

Spoiler:
Code:
import math

def reverse_int(num):
    if num < 10:
        return num
    else:
        ones = num % 10
        rest = num // 10
        return ones * 10 ** int(math.log10(rest) + 1) + reverse_int(rest)

def is_palindrome(n):
    r_int = reverse_int(n)
    if n == r_int:
        return True
    return False

print(is_palindrome(500))
print(is_palindrome(5005))
print(is_palindrome(5))

>>> False
True
True


With goofy on this one. I hate these kinds of questions.
Is there a reason other than didn't think of it/doesn't matter why your is_palindrome function isn't just the 1 line: "return n == reverse_int(n)"? (Honest question, just making sure I understand the ins and outs of python)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:16 PM
Quote:
Originally Posted by Larry Legend
On the subject of interview questions, my friend got a decent one the other day:

Find out if an integer is a palindrome without converting it to a string.

Then part 2 after you answer that:

Spoiler:
Then find out if it is a palindrome without using checking two arrays against each other.
Does this count? I'm not comparing 2 arrays, and technically I'm not converting my original integer to a string, just my reverse array.

Spoiler:

Code:
const myInt = 223344;
const myIntP = 5437345;

function reverseDigits(num, index=1) {
  const digits = [];
  while (num >= 1) {
    digits.push(num % 10);
    num = Math.floor(num / 10);
  }
  return digits.join('')*1;
}

function isPalindrome(num) {
  return num === reverseDigits(num);
}

console.log(isPalindrome(myInt)); // false
console.log(isPalindrome(myIntP)); // true

Last edited by suzzer99; 04-25-2017 at 03:19 PM. Reason: very similar to goofy's
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:21 PM
Yea those are good, I worded the second half wrong.

The second half is doing it without comparing anything to the reverse of it.

(I think the solution is kinda cheesy)

Solution being asked for:

Spoiler:
use Math.log to determine the number of digits in the number, then when you get half way doing modulo, start comparing the numbers against each other going backwards...

I guess that works but seems pretty strange to actually even talk about.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:28 PM
I've been learning SQL for the last 24 hours and I have a new appreciation and empathy for people who have screwed up production databases before.

I can't even change things on my local without nervously checking select and being careful that I know exactly what I'm doing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:31 PM
Quote:
Originally Posted by CyberShark93
So, long story short, I've managed to get a final round face to face interview with Cisco for a graduate role, I recognise that opportunities like this are very hard to come by, so I'd really like to do well, they told me that they will be testing me on 'white board stuff', so whats the best way to prepare for these sort of thing in a week? and any advice at all? (this is my first face to face job interview)
Brag, I got the job! obviously delighted, means that I won't have to bother with job search anymore <3
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:33 PM
Quote:
Originally Posted by Victor
dont you need to turn it into a string before you can split it into an array?
The question asked to not convert to string.

Quote:
Originally Posted by saw7988
Is there a reason other than didn't think of it/doesn't matter why your is_palindrome function isn't just the 1 line: "return n == reverse_int(n)"? (Honest question, just making sure I understand the ins and outs of python)
There is nothing wrong with your suggestion, and I could argue that it is indeed better and more pythonic.

I have a habit of writing things with more verbosity than needed on a first write. I'm also more lispy, so I tend to think in let bindings.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:35 PM
Quote:
Originally Posted by Larry Legend
Yea those are good, I worded the second half wrong.

The second half is doing it without comparing anything to the reverse of it.

(I think the solution is kinda cheesy)
well if you can figure out the length then you can just use math to reconstruct the reverse by %10 and then compare the 2.

ok so if n is the number to check.

Spoiler:
Code:
bool IsPalindrome(n){
  int num = n;
  int count = 0;
  while(num>0){
    num=num/10;
    count=count+1;
  }
  int reverse=0;
  int num2=n;
  while(num2>0){
    reverse = reverse+num2%10*10^(count-1)
    count=count-1;
    num2=num2/10;
  }  
  return (reverse==n)
}


and Im sure there is way to only loop once.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:36 PM
Quote:
Originally Posted by Larry Legend
I've been learning SQL for the last 24 hours and I have a new appreciation and empathy for people who have screwed up production databases before.

I can't even change things on my local without nervously checking select and being careful that I know exactly what I'm doing.
"begin;

do your SQL here

-- commit;
-- rollback;

-- uncomment commit or rollback that you want to use you want to use.
"

Manual transactions are your BFFs.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:38 PM
Quote:
Originally Posted by Larry Legend
Yea those are good, I worded the second half wrong.

The second half is doing it without comparing anything to the reverse of it.

(I think the solution is kinda cheesy)

Solution being asked for:

Spoiler:
use Math.log to determine the number of digits in the number, then when you get half way doing modulo, start comparing the numbers against each other going backwards...

I guess that works but seems pretty strange to actually even talk about.
Yeah that's pretty cool. I knew there had to be something easy to figure out the # of digits. But I felt like googling "how to determine the number of digits" might be cheating.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:38 PM
Quote:
Originally Posted by CyberShark93
Brag, I got the job! obviously delighted, means that I won't have to bother with job search anymore <3
Congrats!!!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:49 PM
And Larry, here is another trick that is super awesome. Not many people know it, but if you have a result set you like and you want to check if your rewrite is accurate, or just see if you are making a mistake on either the initial query or new query:


Code:
select *
from old_query

except all

select *
from new_query

union all

select *
from new_query

except all

select *
from old_query
If you end up with the empty set, you have matching results. If you have results, then you know there is a mistake somewhere. By default union and except remove duplicates. Using "all" returns duplicates.

If you are using PostgreSQL, you should be able to find a procedure for this online. That way you can just do something like "select matching(view_a, view_b);"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:50 PM
Quote:
Originally Posted by CyberShark93
Brag, I got the job! obviously delighted, means that I won't have to bother with job search anymore <3
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-25-2017 , 03:57 PM
Quote:
Originally Posted by CyberShark93
Brag, I got the job! obviously delighted, means that I won't have to bother with job search anymore <3
awesome, sounds like a sweet opportunity
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 02:52 PM
had another candidate come in, same question, did it in about 20 minutes without any outside references
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 03:27 PM
Apparently my friend just got her name on this patent: http://patft.uspto.gov/netacgi/nph-P...F9%2C635%2C195

Which as far as I can tell is just a generic interface to view video content. Lol tech patents always and forever.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 04:45 PM
Tech patent law is some of the dumbest stuff I've seen. It's an area I considered getting into after I graduated from college, and I am so glad I didn't. I have a friend who worked for a company that primary did statistical analysis to be used as expert testimony in court cases. A lot of their work was on patent cases. So much fail all around.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 08:14 PM
I did the same thing as my first real programming job (SAS, stata, perl) but most of our work was on tobacco and auto lawsuits. Your friend didn't work for a company in Novato, CA did he?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 08:17 PM
Quote:
Originally Posted by suzzer99
I did the same thing as my first real programming job (SAS, stata, perl) but most of our work was on tobacco and auto lawsuits. Your friend didn't work for a company in Novato, CA did he?
Nope, Dallas, TX. One of the premiere venues for IP law cases is in a podunk district of Texas. This is because the district is very favorable towards (one side) of IP law disputes.

https://www.eff.org/deeplinks/2014/0...as-its-not-bbq

BTW he now does statistics for a major medical device manufacturer and holy **** do the stories he tells me make me suspicious of medical research.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 08:27 PM
I can guarantee you from working for the pro-tobacco side (yeah, big job satisfaction) that the researchers' studies on tobacco harm we had to counter were often completely full of holes and made up bull****.

This one guy Harrision from Harvard had a reputation as the worst of the bunch. He produced some study which showed a certain curve for some instance of disease vs. smoking prevalence. He provided no supporting data, except to point to the NIH data we all used. My boss gave it to me and said "see if you can replicate this curve".

The curve I got, as he described in his methodology, looked nothing like the pic in his paper. So I started trying different mistakes he could have made - getting closer but still not matching. After two weeks I finally cracked the code. By introducing 3 or 4 different mistakes in the right combination - I perfectly matched his chart.

To this day it remains my proudest programming accomplishment. I burst into my boss' office with the good news, and explained the whole thing to him. He said "that's great but unfortunately it's way too complicated, a jury will never understand it". If Harrison had just made one simple mistake that we could demonstrate, instead of several - it would have been much worse for him. Ugh.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
04-26-2017 , 08:34 PM
Yeah I've heard that before from my friend. The truth is not your ally, unless it's a story you can easily sell to a jury or a (non mathematical) judge. It's actually easier to sell a false pat story than a true complicated one. What can you do. I have literally heard your exact story, down to trying to replicate what "mistakes" a person did to turn the raw data into their conclusions.

I mean, it's not a coincidence that the tobacco industry employs a statistician who makes so many mistakes that are helpful to their cause.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m