Java important practice programs
TCS Codings – 2 def find_equilibrium_index(arr): total_sum = sum(arr) left_sum = 0 for i in range(len(arr)): # right_sum = total_sum – left_sum – arr[i] if left_sum == (total_sum – left_sum – arr[i]): return […]
Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.
Browse CoursesTCS Codings – 2 def find_equilibrium_index(arr): total_sum = sum(arr) left_sum = 0 for i in range(len(arr)): # right_sum = total_sum – left_sum – arr[i] if left_sum == (total_sum – left_sum – arr[i]): return […]
Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: s = “Hello World” Output: 5 Explanation: The last word is “World” with length 5. Example 2: […]
Count the number of vowels in the given string by using queue import java.util.*; class Count { public static void main(String args[]) { String input=”queue”;//4 Queue<Character> q=new LinkedList<>(); int count=0; for(char ch:input.toCharArray())//e { q.add(ch);//e } while(!q.isEmpty())//true { char ch=q.remove(); if(“aeiouAEIOU”.indexOf(ch)!=-1)//indexof returns -1 if value is not found { count++; } […]
//Checking the string is palindrome or not by using stack and queue class Palindrome { public static void main(String args[]) { String str=”madam”; Queue<Charcter> q=new LinkedList<>(); Stack<Character> s=new Stack(); for(char ch:str.toCharArray())//ch=m { q.add(ch);//m s.push(ch);//m } boolean isPalindrome=true; while(!q.isEmpty())//false { if(q.remove()!=s.pop()) { isPalindrome=false; break; } } if(isPalindrome)//true System.out.println(str +”is […]
//reverse a elements of queue by using stack import java.util.*; class ReverseQueue { public static void main(String args[]) { Queue<Integer> q=new LinkedList<>(); q.add(1); q.add(2); q.add(3); Stack<Integer> s=new Stack<>(); while(!q.isEmpty()) { s.push(q.remove()); } while(!s.isEmpty()) { q.add(s.pop()); } System.out.println(“Reverse queue=” +q); } } output: Reverse queue=[3, 2, 1]
Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.
Browse CoursesLearn the fundamentals of programming with Python in this beginner-friendly course.
Master the basics of data analysis, visualization, and machine learning.
Build modern websites with HTML, CSS, JavaScript and popular frameworks.
Learn SEO, social media marketing, email campaigns and analytics.