LinkedIn Interview Question
139 Interview Reviews |
Back to all LinkedIn Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Contract Ruby On Rails Software Engineer at LinkedIn:
Describe a routine which returns the set of integers in {1..100} divisible without remainder by 3 but not by 9.
| Tags: | algorithm, ruby See more , See less 8 |
See more for this LinkedIn Contract Ruby On Rails Software Engineer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (5)
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
0 of 1 people found this helpful
[x for x in range(0,100) if x % 3 == 0 and x % 9 != 0]
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
Loop while(number <= 100)
2) display number
3) number = number+3, display number
4) number = number+6
Loop
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 0 people found this helpful
by Tyler:
Here is a short program I wrote in c++ to show how to solve this problem. Instead of returning the set of integer, I just printed them out on the screen:
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int i = 0;
vector<int> list;
vector<int>::iterator it;
for(i = 1; i <= 100; i++)
{
if(i%3 == 0 && i%9 != 0)
{
list.push_back(i);
}
}
for(it = list.begin(); it != list.end(); it++)
{
cout << *it << endl;
}
return 0;
}
If I missed anything, please let me know. Happy coding and problem solving!