├── max in array ├── two sum ├── ascending and descending └── second largest /max in array: -------------------------------------------------------------------------------- 1 | package day1z; 2 | import java.util.*; 3 | public class Day1z { 4 | public static void main(String[] args) { 5 | Scanner s=new Scanner(System.in); 6 | int i; 7 | int n=s.nextInt(); 8 | int[] a=new int[n]; 9 | for(i=0;imax) { 13 | max=a[i]; 14 | } 15 | } 16 | System.out.println(max); 17 | 18 | } 19 | 20 | } 21 | 22 | op: 23 | 2 24 | 9 25 | 8 26 | 9 27 | 28 | -------------------------------------------------------------------------------- /two sum: -------------------------------------------------------------------------------- 1 | Input: nums = [2,7,11,15], target = 9 2 | Output: [0,1] 3 | Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. 4 | 5 | 6 | class Solution { 7 | public int[] twoSum(int[] nums, int target) { 8 | for(int i=0;ia[j]) { 13 | int temp=a[i]; 14 | a[i]=a[j]; 15 | a[j]=temp; 16 | } 17 | } 18 | } 19 | for(int i=0;ia[j]) 16 | { 17 | temp=a[i]; 18 | a[i]=a[j]; 19 | a[j]=temp; 20 | } 21 | } 22 | } 23 | for(int i=n-1;i>0;i--) 24 | { 25 | if(a[i]==a[i-1]) 26 | { 27 | continue; 28 | } 29 | else 30 | { 31 | System.out.println(a[i-1]); 32 | break; 33 | } 34 | } 35 | } 36 | } 37 | --------------------------------------------------------------------------------