The tag has no wiki summary.

learn more… | top users | synonyms (1)

4
votes
2answers
136 views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are ...
1
vote
1answer
95 views

Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the ...
2
votes
2answers
118 views

string to integer (implement atoi)

Implement atoi to convert a string to an integer. Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is ...
1
vote
2answers
98 views

remove all nodes with same value in a linked list

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return ...
5
votes
4answers
184 views

plus one(interview question)

Given a number represented as an array of digits, plus one to the number. input expected [8,9,9,9] [9,0,0,0] [1,0,0,0,0] [1,0,0,0,1] ...
3
votes
3answers
111 views

Length of last word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is ...
3
votes
2answers
116 views

remove duplicates in a sorted array if duplicates are allowed at most twice

Given a sorted array, remove the duplicates in place such that each element appear at most twice and return the new length. Do not allocate extra space for another array, you must do this in place ...
0
votes
0answers
16 views

remove duplicates in a sorted array [duplicate]

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with ...
1
vote
0answers
43 views

maximize assonance in a string(interview question)

Question: Assonance is the reiteration of the same vowel sound at the beginning of several consecutive words. Assume that each vowel(A, E, I, O, and U) has only one sound. Prompt the user for ...
1
vote
2answers
79 views

Calculate difference of two ranges given

Write a method to compute the difference between two ranges. A range is defined by an integer low and an integer high. A - B (A “minus” B) is “everything in A that is not in B”. This is an interview ...
4
votes
3answers
215 views

interview question, friends, movies and likes

I was recently asked to implement an interface for a job interview. the class has methods to add customers and movies, the customers can watch or like movies and add friends. there are methods to get ...
0
votes
3answers
196 views

Run Length Encoding

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is “wwwwaaadexxxxxx”, then the function should ...
5
votes
5answers
1k views

Finding repeating numbers in an array

I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to ...
6
votes
4answers
371 views

Critique: readability of java interview question

In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following: Given two sorted arrays, A and B. Write a method merging the elements of ...
4
votes
1answer
159 views

Improving a Swedish Tax Calculator

I'm submitting this code in a couple of days as part of an an interview process. The company knows that I don't have any formal experience with Java. I'm hoping they are testing my ability to learn ...
6
votes
4answers
1k views

c++ implementation of Trie data structure

I use Trie data structure to solve the following problem: Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then ...
0
votes
2answers
209 views

Given a sequence of words, print all anagrams together

Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be “cat tac act dog god”. My idea is to sort ...
3
votes
1answer
168 views

Interview example [closed]

Recently I participated in an interview for a Russian company in Moskow and could not answer some of the simple questions. One of them I would like to ask here. List all problems which you can see in ...
5
votes
4answers
741 views

Find missing number from list

I was asked a question in an interview the other day, the question was: "You have an array list of numbers from 1 to 100, the problem is that one number is missing. How would you find that number?" ...
7
votes
4answers
627 views

Reverse each word of a string in C

I had this interview question like a year ago, I was asked to code on a piece of paper how to reverse each word of a string. Since I am used to java I proposed the obvious answer of using split + ...
2
votes
1answer
208 views

Lexicographic rank of a string

Given a string, find its rank among all its permutations sorted lexicographically. For example, rank of “abc” is 1, rank of “acb” is 2, and rank of “cba” is 6. Assuming there is no duplicated ...
5
votes
1answer
274 views

How can I improve my algorithm?

This is a problem from Interview Street in Dynamic Programming section. https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb Billboards(20 points) ADZEN is a very ...
9
votes
3answers
278 views

Reversing a linked list

I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
0
votes
1answer
355 views

Reverse a linked list [closed]

Problem: create a linked list and reverse the list appending with '<-'. Example, if the linked list is [1,2,3,4,5,6], so the result is 5 <- 4 <- 3 <- 2 <- 1. Here is the code class ...
2
votes
2answers
176 views

the number of connected component

Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, M(x1, y1) == -1 && M(x2, y2) == -1 && |x1-x2|+|y1-y2|=1 ...
5
votes
2answers
723 views

reverse every word in a string(should handle space)

Examples: char test1[] = " "; char test2[] = " hello z"; char test3[] = "hello world "; char test4[] = "x y z "; Results: " " " olleh z" "olleh dlrow " "x ...
5
votes
2answers
680 views

pascal triangle in php (anything wrong with this solution?)

I saw that one of the interview questions could be building a pascal triangle. Is there anything wrong with this particular solution I came up with? function pascal_r($r){ $local = array(); ...
6
votes
3answers
259 views

Exception handling, et al - How do I make this not “poor”?

I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions: Why is this error handling considered poor? How am I supposed to be doing it? ...
0
votes
2answers
285 views

Optimization in overcoming TLE in interviewStreet problem

I have been trying to get the problem Quadrant Queries correct for a while now. Although my approach is an optimal one, I am getting a TLE on 3 test cases. Please help me optimize my approach so that ...
1
vote
1answer
137 views

C/C++ code to do customized string comparing

It's an interview question, I was asked to compare 2 strings, and the number in the string are evaluated to integers when comparing. I can use C/C++ and can not use stl or stdlib. Some test cases ...
3
votes
3answers
719 views

critique my implementation of hash map

I was asked to implement a hash map in this phone interview (screen-share), so time was limited and this is what I came up with. I'd appreciate if someone can take a minute to critique/review it and ...
4
votes
6answers
622 views

Writing FizzBuzz

First of all: I came up with that question on SO already. But I am offered different solution which are "better" in some ways. The goal is to improve this specific version, not to create another one. ...
5
votes
3answers
960 views

Approximate String Matching Interview Question

I was working on the challenge Save Humanity from Interviewstreet for a while then gave up, solved a few other challenges, and have come back to it again. The code below generates the correct ...
1
vote
2answers
6k views

Deleting a node from Binary Search Tree

I have read about it at few places and tried to write my own version, would like to get it reviewed. class Node { private int value; private Node left; private Node right // ...
1
vote
1answer
961 views

Implement a function to check if a tree is balanced

Yet another interview question: Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ ...
3
votes
4answers
938 views

Describe how you could use a single array to implement three stacks

I'm preparing for an interview so I'm trying to solve some problems to stretch my mind. Here is one: Describe how you could use a single array to implement three stacks. And here is my ...
5
votes
6answers
1k views

Printing stars - simple interview problem

I just got back from my interview and there was this one problem that I'm wondering if there was a better solution. Here's the problem: Write a C++ program that prints the following pattern using ...
3
votes
5answers
1k views

FizzBuzz implementation

The common FizzBuzz implementation I saw is using a check for % 15 for printing "FizzBuzz" Would you let me know if there is anything wrong / better with this approach? public class FizzBuzz { ...
3
votes
1answer
392 views

Java: Find the smallest integer not in the list - Memory Efficiency

This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically ...
-2
votes
1answer
678 views

Project Euler Problem 13 [closed]

Hi. I'm a novice C programmer. I'm trying to solve problem 13 but I feel as if my solution isn't as elegant as it could be. Can you please help me by providing me with advice on how to solve this ...
2
votes
7answers
843 views

Optimize an Anagram Checker

Two words are anagrams of each other if they contain the same letters, ie pots == stop I'm working through interview questions. The easiest way to check is to sort both words, then compare. But ...
3
votes
3answers
407 views

Possible combinations of bills that sum to the given amount

Question: You are given an array that represents bills in certain currency (for example 1, 2, 5, 10) and an amount, for example 17. You should output the number of possible combinations of ...
2
votes
3answers
892 views

Better implementation of a simplified regular expression engine?

Task: On an alphabet set [a-z], a simplified regular expression is much simpler than the normal regular expression. It has only two meta characters: '.' and '*'. '.' -- exact one arbitrary ...
4
votes
4answers
5k views

Converting int value to String without using toString and parseInt method

I am studying about the converting int to string and string to int without using toString and parseInt method. I already made methods. However, I don't believe that my way of doing was the best. I ...
2
votes
2answers
579 views

Ways to improve my coding test FizzBuzz solution for a TDD role?

I had an interview recently where I was asked to produce the traditional FizzBuzz solution: Output a list of numbers from 1 to 100. For all multiples of 3 and 5, the number is replaced ...
3
votes
2answers
835 views

PHP Fizz Buzz interview question code

Reading Jeff Atwood's "Why Can't Programmers.. Program?" led me to think that almost all of the solutions would not be something I would want in my own code-base. The Fizz Buzz program specification ...
2
votes
3answers
352 views

What is the security issue in this code?

I was asked how this code has a security risk. Does anyone have any ideas what it is? I am new on the security topic and don't know what to look for. String DBdriver = "com.ora.jdbc.Driver"; String ...
19
votes
2answers
1k views

Interview screw up after this piece of code

I was screwed up after submitting this piece of work. But I have no feedback to know what "BAD" things inside this block of code. The requirements are like this: Connect to the server on a ...
3
votes
1answer
642 views

Sample finite-state machine interview question

We have interviewees write sample code, but now want them to modify some simple working code. I came up with the following proposal; it is a syntax-directed interpreter implemented with a table-driven ...
39
votes
15answers
5k views

Critique requested on the program to output the names without repetitions with the number of occurrences in order of decreasing repetitions.

A short while ago, I have submitted a coding exercise to a potential employer. The response came back the next morning and you can guess what it was from the subject of this post. I am not ...

1 2