java Sol :
public class HelloWorld{ public static void main(String []args){ int[] arr=new int[]{2, 7, 3, 4}; int[] rez=new int[arr.length]; int som=1; for(int i=0;i<arr.length;i++){ if(i==0){ for(int j=i+1;j<arr.length;j++) som*=arr[j]; rez[i]=som; }else{ rez[i]=(som/arr[i])*arr[i-1]; som=rez[i]; } } for(int i=0;i<arr.length;i++) System.out.println(rez[i]); } }
you could optimize this solution for O(n)
hello, i am new but it is O(n) right ? without the last loop ofc
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
java Sol :
you could optimize this solution for O(n)
hello,
i am new but it is O(n) right ? without the last loop ofc