fix23 challenge

Hi,

i am trying below challenge

http://codingbat.com/prob/p120347

i wrote as below

public int[] fix23(int[] nums) {

int numsNew[]=new int[3];
numsNew=nums;
numsNew[1]=0;
  if(nums[1]==nums[2])
  return numsNew;
  else 
  return nums;
}

Open in new window


i am failing below
xpected      Run            
fix23({1, 2, 3}) → {1, 2, 0}      {1, 0, 3}      X         
fix23({2, 3, 5}) → {2, 0, 5}      {2, 0, 5}      OK         
fix23({1, 2, 1}) → {1, 2, 1}      {1, 0, 1}      X         
fix23({3, 2, 1}) → {3, 2, 1}      {3, 0, 1}      X         
fix23({2, 2, 3}) → {2, 2, 0}      {2, 0, 3}      X         
fix23({2, 3, 3}) → {2, 0, 3}      {2, 0, 3}      OK         
other tests

how to improve and fix my code. please advise
LVL 7
gudii9Asked:
Who is Participating?
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.

ozoCommented:
for( int i=1;i<3;++i ){
    if( nums[i-1]==2&&nums[ i ]==3 ){ nums[ i ]=0; }
  }
  return nums;
0
ozoCommented:
does nums[1]==nums[2] have any connecton to there is a 2 in the array immediately followed by a 3?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
krakatoaCommented:
public int[] fix23(int[] nums) {

  return nums[0]==2&&nums[1]==3?new int[]{2,0,nums[2]}:nums[1]==2&&nums[2]==3?new int[]{nums[0],2,0}:nums;
  
}

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

gudii9Author Commented:
public int[] fix23(int[] nums) {

int numsNew[]=new int[3];
int len =nums.length;
numsNew=nums;
for(int i=0;i<=len-2;i++)
{
if((nums[i]==2)&(nums[i+1]==3))
{
   numsNew[i+1]=0;
  }
  }
  return numsNew;
}

Open in new window


i wrote as below and passed all tests.

Expected      Run            
fix23({1, 2, 3}) → {1, 2, 0}      {1, 2, 0}      OK         
fix23({2, 3, 5}) → {2, 0, 5}      {2, 0, 5}      OK         
fix23({1, 2, 1}) → {1, 2, 1}      {1, 2, 1}      OK         
fix23({3, 2, 1}) → {3, 2, 1}      {3, 2, 1}      OK         
fix23({2, 2, 3}) → {2, 2, 0}      {2, 2, 0}      OK         
fix23({2, 3, 3}) → {2, 0, 3}      {2, 0, 3}      OK         
other tests
OK         


Does below supposed to pass?
fix23({3, 2, 4}) → {0, 2, 4}      {0,2, 4}      OK
0
krakatoaCommented:
Does below supposed to pass?

No.
0
gudii9Author Commented:
No.
Given an int array length 3, if there is a 2 in the array immediately followed by a 3, set the 3 element to 0. Return the changed array.

is it because 2 followed 3 means  always 3 should come afgter 2 not otherway(3 should come before 2 still that is following right??sorry english is not my first language??)
0
ozoCommented:
0
gudii9Author Commented:
1 a: to go or come after or behind (someone or something)

i saw the link it says after or behind both??
please advise
0
ozoCommented:
In this context:
{2    ,     3}
^           ^       
before      after
^           ^
front       back
mean the same thing

Open in new window

0
gudii9Author Commented:
got it. So 2 should come before then 3 should come after (that is like saying 2 in the array immediately followed by a 3
that is why below came like this without replacing 3 with 0
fix23({3, 2, 1}) → {3, 2, 1}      {3, 2, 1}

)

now i take follow means after to make it easy
0
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
Java

From novice to tech pro — start learning today.