diff --git a/December 01/question1.txt b/December 01/question1.txt new file mode 100644 index 0000000..8cb9c75 --- /dev/null +++ b/December 01/question1.txt @@ -0,0 +1,17 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + int[] arr=new int[n-1]; + int sum=0; + for(int i=0;iarr[i+1]){ + t=arr[i]; + arr[i]=arr[i+1]; + arr[i+1]=t; + } + + if(i%2!=0&&arr[i]1) + return "not possible"; + else + { + if(n1>=n2) + { + for(int i=0;il1=new ArrayList<>(); + for(int i=0;i1) + { + j=(j+k-1)%l1.size(); + l1.remove(j); + } + System.out.print(l1.get(0)); + } +} diff --git a/December 06/question6.txt b/December 06/question6.txt new file mode 100644 index 0000000..1d39407 --- /dev/null +++ b/December 06/question6.txt @@ -0,0 +1,31 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + int target=s.nextInt(); + int[] arr=new int[n]; + for(int i=0;ih1=new HashMap<>(); + HashSet set = new HashSet<>(); + for (int i = 0; i >l1=new ArrayList<>(); + for(int i=0;icur=new ArrayList<>(); + cur.add(1); + for(int j=1;j0) + cur.add(1); + + l1.add(cur); + } + System.out.print(l1); + } +} diff --git a/December 08/question8.txt b/December 08/question8.txt new file mode 100644 index 0000000..8ba91c7 --- /dev/null +++ b/December 08/question8.txt @@ -0,0 +1,25 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + solution(n); + } + public static void solution(int n) + { + int s,res=0,j; + for(int i=1;i<=n;i++) + { + s=0; + j=i; + while(j>0) + { + int r=j%10; + s+=r*r; + j/=10; + } + res+=s; + } + System.out.print(res); + } +} diff --git a/December 09/question9.txt b/December 09/question9.txt new file mode 100644 index 0000000..6db2474 --- /dev/null +++ b/December 09/question9.txt @@ -0,0 +1,24 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + Listl1=new ArrayList<>(); + for(int i=0; il1) + { int c=0; + for(int i=0; i 0: + name, tickets = queue.popleft() + if tickets <= remaining_tickets: + remaining_tickets -= tickets + results.append(f"{name} purchased {tickets} tickets") + else: + results.append(f"{name} purchased {remaining_tickets} tickets") + remaining_tickets = 0 + + process_queue(vip_queue) + process_queue(regular_queue) + + for queue in [vip_queue, regular_queue]: + while queue: + name, _ = queue.popleft() + results.append(f"{name} was not served") + + return results + +def get_dynamic_input(): + N = int(input("Enter the total number of tickets available: ")) + requests = [] + print("Enter ticket requests (name, number of tickets, optional VIP). Type 'done' to finish:") + while True: + request = input().strip() + if request.lower() == "done": + break + requests.append(request) + return N, requests + +N, requests = get_dynamic_input() +output = process_ticket_requests(N, requests) +for line in output: + print(line) diff --git a/December 13/question13.txt b/December 13/question13.txt new file mode 100644 index 0000000..ea16357 --- /dev/null +++ b/December 13/question13.txt @@ -0,0 +1,41 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + Listl1=new ArrayList<>(); + for(int i=0;il1) + { + int s,pre=0,c=0,j,x=0; + for(int i=0;il1.get(j)) + { + s=l1.get(j); + x=j; + } + } + if(s!=pre && i != x&& swap(i,x,l1)) + c++; + pre=s; + } + System.out.print(c); + } + public static boolean swap(int i,int j,Listl1) + { + int temp = l1.get(i); + l1.set(i, l1.get(j)); + l1.set(j, temp); + return true; + } +} diff --git a/December 14/question14.txt b/December 14/question14.txt new file mode 100644 index 0000000..98a70bb --- /dev/null +++ b/December 14/question14.txt @@ -0,0 +1,53 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int test = sc.nextInt(); + StringBuilder result = new StringBuilder(); + while (test-- > 0) { + int n = sc.nextInt(); + int k = sc.nextInt(); + int d = sc.nextInt(); + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = sc.nextInt(); + } + if (cal(n,k,d,arr)) { + result.append("yes\n"); + } else { + result.append("no\n"); + } + } + System.out.println(result); + sc.close(); + } + + public static boolean cal(int n, int k, int d, int[] arr) { + HashMap h1 = new HashMap<>(); + for (int num : arr) { + h1.put(num, h1.getOrDefault(num, 0) + 1); + } + if (h1.size() < k) + return false; + HashSet team1 = new HashSet<>(); + int[] freq = new int[n + 1]; + int l = 0; + for (int r = 0; r < n; r++) { + freq[arr[r]]++; + team1.add(arr[r]); + while (team1.size() > k) { + freq[arr[l]]--; + if (freq[arr[l]] == 0) { + team1.remove(arr[l]); + } + l++; + } + int team1_size = r - l + 1; + int team2_size= n - team1_size; + if (Math.abs(team1_size - team2_size) <= d && team1.size() == k) { + return true; + } + } + return false; + } +} diff --git a/December 15/question15.txt b/December 15/question15.txt new file mode 100644 index 0000000..2ae56f7 --- /dev/null +++ b/December 15/question15.txt @@ -0,0 +1,30 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + int[] arr=new int[n]; + int w=s.nextInt(); + for(int i=0;iw) + { + s=arr[i]; + t++; + } + } + if(s>0) + t++; + System.out.print(t); + } +} diff --git a/December 16/question16.txt b/December 16/question16.txt new file mode 100644 index 0000000..25feeed --- /dev/null +++ b/December 16/question16.txt @@ -0,0 +1,41 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s1=new Scanner(System.in); + int n=s1.nextInt(); + int n1=s1.nextInt(); + int[] arrival=new int[n]; + int[] departure=new int[n1]; + for(int i=0;iarrival[j]) + { + int temp=arrival[i]; + arrival[i]=arrival[j]; + arrival[j]=temp; + + int temp1=departure[i]; + departure[i]=departure[j]; + departure[j]=temp1; + } + } + int min = arrival[0]; + int max=departure[0]; + for(int i=1;iarrival[i]) + c++; + else + { + min=arrival[i]; + max=departure[i]; + } + } + System.out.println(c); + } } diff --git a/December 18/question18.txt b/December 18/question18.txt new file mode 100644 index 0000000..fd5fc27 --- /dev/null +++ b/December 18/question18.txt @@ -0,0 +1,41 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner ss=new Scanner(System.in); + String s=ss.next(); + int start=0,end=0; + for(int i=0;iend-start) + { + start=i-((total-1)/2); + end=i+(total/2); + } + } + String newstr= s.substring(start,end+1); + int c=0; + for(int i=0;ir) + return 0; + while(l>=0 && r>l1=new ArrayList<>(); + l1=solution(arr,target); + System.out.print(l1.size()); + } + public static List> solution(int[] arr,int t) + { + List>l2=new ArrayList<>(); + comb(arr,t,l2,new ArrayList<>()); + return l2; + } + public static void comb(int[] arr,int t,List> l2,List cur) + { + if(t==0) + { + l2.add(new ArrayList<>(cur)); + return; + } + for(int ind=0;ind s) { + flag=false; + break; + } + s = Math.max(s, i + arr[i]); + if (s >= n - 1) { + flag=true; + break; + } + } + if(flag) + System.out.print("true"); + else + System.out.print("false"); + } +} + diff --git a/December 27/question27.txt b/December 27/question27.txt new file mode 100644 index 0000000..22b0194 --- /dev/null +++ b/December 27/question27.txt @@ -0,0 +1,29 @@ +import java.util.*; +class Main { + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n=s.nextInt(); + int[] arr=new int[n]; + for(int i=0;i rightmax=new Stack(); + rightmax.push(arr[arr.length-1]); + for(int i=arr.length-2;i>=2;i--) + { + int temp=Math.max(rightmax.peek(),arr[i]); + rightmax.push(temp); + } + int totalwater=0; + for(int i=1;i