Amazon Interview Question

Write a code to detect the first number having duplicate in below mentioned Array. Array = [4 1 2 5 8 1 3] Output would be 1. Note : You can use any coding or scripting language.

Interview Answers

Anonymous

May 16, 2017

RUBY: a = [4, 1, 2, 5, 8, 1, 3] b = a.detect do |e| a.count(e) > 1 end print b Output : 1

Anonymous

May 7, 2021

public class Try { public static void main(String []args){ int[] a= {4,1,2,5,8,1,3,8}; int counter=1; for(int i=0;i

2

Anonymous

Nov 16, 2016

int a [] ={4,5,5,1,2,1,2}; loop:for(int i=0; i

2