# no23 challenge

Hi,

i am trying

http://codingbat.com/prob/p175689
``````public boolean no23(int[] nums) {

int len=nums.length;

for(int i=0;i<=len-1;i++)
{
if(nums[i]==2 | nums[i]==3)
return false;

else
return true;
}

return false;
}
``````

LVL 7
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
return (nums[0]&~1)!=2&&(nums[1]|1)!=3;

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
or
``````public boolean no23(int[] nums) {

int len=nums.length;

for(int i=0;i<=len-1;i++)
{
if(nums[i]==2 | nums[i]==3)
return false;

//else
//return true;
}

return /*false*/true;
}
``````
Commented:
this works

public int[] makeEnds(int[] nums) {
return new int[]{nums[0],nums[Math.max(0,nums.length-1)]};
}
Author Commented:
return /*false*/true;

i see above additional line compared to my code  as above what it means by above line?

also what is meaning of below

return (nums[0]&~1)!=2&&(nums[1]|1)!=3;

Author Commented:
``````public boolean no23(int[] nums) {

return new int[]{nums[0],nums[Math.max(0,nums.length-1)]};
}
``````

above giving below error
Compile problems:

Error:      return new int[]{nums[0],nums[Math.max(0,nums.length-1)]};
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type mismatch: cannot convert from int[] to boolean

see Example Code to help with compile problems

Commented:
Oh sorry, I did answer to another challenges

here is the correct answer :

``````public boolean no23(int[] nums) {
return (nums[0]!=2 && nums[0]!=3  && nums[1]!=2 && nums[1]!=3);
}
``````

It will return true if :

Number1 is not 2             (nums[0]!=2)
AND Number1 is not 3             (&& nums[0]!=3)
AND Number2 is not 2             (&& nums[1]!=2)
AND Number2 is not 3             (&& nums[1]!=3)
Commented:
return /*false*/true;
means
return true;

return (nums[0]&~1)!=2&&(nums[1]|1)!=3;
means
return (nums[0]!=2&&nums[0]!=3)&&(nums[1]!=2&&nums[1]!=3);

nums[0]&~1 == 2 when nums[0]==2 or nums[0]==3
nums[1]|1 == 3 when nums[1]==2 or nums[1]==3
Author Commented:
return /*false*/true;
means
return true;

in above code
/*false*/ false is surrounded with comment right?
Author Commented:
return (nums[0]&~1)!=2&&(nums[1]|1)!=3;
means
return (nums[0]!=2&&nums[0]!=3)&&(nums[1]!=2&&nums[1]!=3);

is above ~ is java 8 syntax like lambda?

return (nums[0]!=2&&nums[0]!=3)&&(nums[1]!=2&&nums[1]!=3);

how is above with brakets different from below

return (nums[0]!=2 && nums[0]!=3  && nums[1]!=2 && nums[1]!=3);

without any brackets?
Commented:
(nums[0]&~1)==2 when nums[0]==3

parenthesis are unnecessary in
return nums[0]!=2 && nums[0]!=3 && nums[1]!=2 && nums[1]!=3;
Author Commented:
``````return (nums[0]!=2&&nums[0]!=3)&&(nums[1]!=2&&nums[1]!=3);

nums[0]&~1 == 2 when nums[0]==2 or nums[0]==3
nums[1]|1 == 3 when nums[1]==2 or nums[1]==3
``````

above solution is not clear.
how it check no 2 or no 3 in the given array for different lenghts.

any simple examples on ~
Commented:
``````public boolean no23(int[] nums) {
for( int i : nums ){
if( i==2||i==3 ){ return false; }
}
return true;
}
``````
``````public boolean no23(int[] nums) {
for( int i : nums ){
if( (i&~1)==2 ){ return false; }
}
return true;
}
``````
``````public boolean no23(int[] nums) {
for( int i : nums ){
if( (i|1)==3 ){ return false; }
}
return true;
}
``````
``````public boolean no23(int[] nums) {
for( int i : nums ){
if( i/2==1 ){ return false; }
}
return true;
}
``````
Author Commented:
``````public boolean no23(int[] nums) {
for( int i : nums ){
if( i==2||i==3 ){ return false; }
}
return true;
}
``````

above is clear.

if( (i&~1)==2 ){ //what it means by i&~1 means ??

if( (i|1)==3 ){ //what it means by i|1 ??

if( i/2==1 ){ //how it checks no 2 as well as no 3.  is it due to division operator only 2, 3 divisible with 1 as result? if i take  i value as 4 then result is 2 which is not equal to 1 so true right??
Author Commented:
Commented:
Author Commented:
1 = 0001
2 = 0010
3 = 0011

2 0010
1 0001 or
----
3 0011

3 0011
1 0001 or
----
3 0011

Bitwise OR is clear but bitwise AND solution as below is not clear.
return (nums[0]&~1)!=2&&(nums[1]|1)!=3;
Author Commented:
2    0010
~1 1110 AND
-------------------
2  0010

3    0011
~1 1110 AND
----------------
2   0010

nums[1]|1
2 0010
1 0001 OR
-----------
3 0011
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.