Note: Both arrays will be length 1 or more.
Check Below Code:
package com.test.arrays;
public class CommonArrayEnd
{
public static void main(String args[])
{
CommonArrayEnd ca = new CommonArrayEnd();
System.out.println(ca.commonEnd(new int[] {1, 2, 6}, new int[] {1, 2, 6}));
System.out.println(ca.commonEnd(new int[] {1, 2, 3}, new int[] {7, 3, 2}));
System.out.println(ca.commonEnd(new int[] {1, 2, 3}, new int[] {1}));
}
public boolean commonEnd(int[] a, int[] b)
{
return (a[0] == b[0] || a[a.length-1] == b[b.length-1]);
}
}
Output
true
false
true