From 2b0c41fb9c1e2c37d2008de7f10d199aa66ac8c8 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Sat, 3 Feb 2024 23:59:39 +0530 Subject: [PATCH] Added codes for 3 Feb --- GeeksForGeeks/February/3-2-24/GFG.java | 117 ++++++++++++++++++++++++ GeeksForGeeks/February/3-2-24/README.md | 2 + LeetCode/February/3-2-24/README.md | 2 + LeetCode/February/3-2-24/Solution.java | 24 +++++ 4 files changed, 145 insertions(+) create mode 100644 GeeksForGeeks/February/3-2-24/GFG.java create mode 100644 GeeksForGeeks/February/3-2-24/README.md create mode 100644 LeetCode/February/3-2-24/README.md create mode 100644 LeetCode/February/3-2-24/Solution.java diff --git a/GeeksForGeeks/February/3-2-24/GFG.java b/GeeksForGeeks/February/3-2-24/GFG.java new file mode 100644 index 0000000..b320928 --- /dev/null +++ b/GeeksForGeeks/February/3-2-24/GFG.java @@ -0,0 +1,117 @@ +//{ Driver Code Starts +import java.util.*; +class Node +{ + int data; + Node next; + Node(int d) + { + data = d; + next = null; + } +} + +class LinkedList1 +{ + Node head; // head of lisl + /* Inserts a new Node at front of the list. */ + public void addToTheLast(Node node) + { + if (head == null) + { + head = node; + } + else + { + Node temp = head; + while (temp.next != null) + temp = temp.next; + + temp.next = node; + } + } + /* Function to print linked list */ + void printList() + { + Node temp = head; + while (temp != null) + { + System.out.print(temp.data+" "); + temp = temp.next; + } + System.out.println(); + } + public static void main(String args[]) + { + Scanner sc = new Scanner(System.in); + int t=sc.nextInt(); + String s = sc.nextLine(); + while(t>0) + { + int n = sc.nextInt(); + String s1 = sc.nextLine(); + LinkedList1 llist = new LinkedList1(); + + if (n > 0) + { + int a1=sc.nextInt(); + Node head= new Node(a1); + llist.addToTheLast(head); + } + for (int i = 1; i < n; i++) + { + int a = sc.nextInt(); + llist.addToTheLast(new Node(a)); + } + System.out.println(new Solution().DecimalValue(llist.head)); + t--; + } + } +} + + +// } Driver Code Ends + + +/* Node of a linked list + class Node { + int data; + Node next; + Node(int d) { data = d; next = null; } +} + Linked List class +class LinkedList +{ + Node head; // head of list +} +This is method only submission. You only need to complete the method. */ + +class Solution +{ + long DecimalValue(Node head) + { + ArrayList list=new ArrayList<>(); + long mod=(long)1000000007; + Node curr=head; + while(curr!=null) + { + list.add(curr.data); + curr=curr.next; + } + + Collections.reverse(list); + long base=1; + long ans=0; + int i=0; + while(i= 0; start--) + { + int currMax = 0; + int end = Math.min(N, start + k); + + for (int i = start; i < end; i++) + { + currMax = Math.max(currMax, arr[i]); + dp[start % K] = Math.max(dp[start % K], dp[(i + 1) % K] + currMax * (i - start + 1)); + } + } + return dp[0]; + } +}