learner
BAN USER- 11of 15 votes
AnswersGiven an int array which might contain duplicates, find the largest subset of it which form a sequence.
- learner in -
Eg. {1,6,10,4,7,9,5}
then ans is 4,5,6,7
Sorting is an obvious solution. Can this be done in O(n) time| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Software Engineer / Developer Arrays Algorithm - 0of 0 votes
Answers#include<stdio.h> int main() { int i,j; j = 10; i = 3; //i = j++ - j++; //i = i++ + ++i; //i = j++ - j++ + i++ + ++i; printf("%d\n", i); }
If I un-comment the first comment then output = 0
- learner in India
if second then output = 9
if third then output = 8
Please explain why this is so| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer
#include<stdio.h>
int main() {
int i,j;
j = 10;
i = 3;
//i = j++ - j++;
//i = i++ + ++i;
//i = j++ - j++ + i++ + ++i;
printf("%d\n", i);
}
~
If I un-comment the first comment then output = 0
if second then output = 9
if third then output = 8
Please explain why this is so
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Arrarys;
/**
*
* @author swapnil
*/
public class powers2i5j {
public static void main(String[] args) {
int[] ans = new int[100];
ans[0] = 1;
int m = 0; //2
int n = 0; //5
int i = 1;
for (int j = 1; j < 100; j++) {
int n5 = ans[n] * 5;
int m2 = ans[m] * 2;
if (n5 < m2) {
ans[i] = n5;
i++;
System.out.print(n5 + ", ");
n++;
} else if (n5 > m2) {
ans[i] = m2;
i++;
System.out.print(m2 + ", ");
m++;
} else {
ans[i] = n5;
i++;
System.out.print(m2 + ", ");
m++;
n++;
}
}
}
}
Think binary !
- learner May 16, 2012