GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — HackerRank/NewClass2.java at master · addhari/HackerRank Expand file tree/ Copy pathNewClass2.javaMore file actions 84 lines (67 loc) · 2.01 KB / Copy pathNewClass2.javaFile metadata and controls84 lines (67 loc) · 2.01 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hackerrank; import java.util.Arrays; /** * * @author Harry */ public class NewClass2 { public static void main(String[] args) { int[] h={1,2}; int[] v={6,1,2,6,3,4,5,6,7,8,9,6}; NewClass2 n=new NewClass2(); //n.prison(3,2, h, v); n.firstAndLast(v,6); } void firstAndLast(int[] arr,int x) { int startingIndex=-1; int lastIndex=-1; for(int i=0;i<Math.floor(arr.length)&&(startingIndex==-1||lastIndex==-1);i++) { if(arr[i]==x&&startingIndex==-1)startingIndex=i; if(arr[arr.length-1-i]==x&&lastIndex==-1)lastIndex=arr.length-1-i; if((startingIndex!=-1)&&(lastIndex!=-1))break; } if(startingIndex!=lastIndex) System.out.println(startingIndex+","+lastIndex); else System.out.println("-1"); } long prison(int n, int m, int[] h, int[] v) { int vMax=0; int hMax=0; int temp=2; Arrays.sort(h); Arrays.sort(v); if(h.length>0)hMax=2; if(v.length>0)vMax=2; for(int i=0;i<h.length-1;i++) { if(h[i+1]-h[i]==1) { temp++; if(temp>hMax) hMax=temp; } else temp=2; } temp=2; for(int i=0;i<v.length-1;i++) { if(v[i+1]-v[i]==1) { temp++; if(temp>vMax) vMax=temp; } else temp=2; } System.out.println(hMax+","+vMax); System.out.println(vMax*hMax); return vMax*hMax; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |