Cisco Systems Interview Question
SDE-2sCountry: United States
Interview Type: In-Person
I'm not too sure I understood what the question was completely but here is the code that I wrote:
public class testint {
public static void main(String[] args) {
String[] test = args;
function("1xxx","1000",test);
//System.out.println(args);
}
public static void function(String ID, String mask,String[] str)
{
char[] idnotx = new char[ID.length()];
char[] masknot0 = new char [mask.length()];
char idval = 'x';
char maskval = 'x';
idnotx = ID.toCharArray();
masknot0=mask.toCharArray();
int pos = -1;
int pos0 = -1;
for(int i = 0;i<ID.length(); i++)
{
if(idnotx[i] != 'x')
{
pos = i;
idval = idnotx[i];
}
}
for(int i=0;i<mask.length();i++)
{
if(masknot0[i] != '0')
{
pos0 = i;
maskval = masknot0[i];
}
}
for(int i = 0; i<str.length; i++)
{
char[] temp = new char[str[i].length()];
temp = str[i].toCharArray();
if(temp[pos0] == idval)
System.out.println(str[i]);
}
//System.out.println(pos);
//System.out.println(pos0);
//System.out.println(idval);
//System.out.println(maskval);
//System.out.println(str.length);
}
}
Here are the results:
C:\Users\Admin\Desktop>javac testint.java
C:\Users\Admin\Desktop>java testint 1001 0101 1100 0011 1111 0000 0001
1001
1100
1111
How is the result computed? Does an element needs to pass all of the filters or any one of them?
- Balajiganapathi S August 14, 2014