Java Hyd Team
746 subscribers
986 photos
39 videos
670 files
690 links
https://teamhydteam.my.canva.site/

Can visit us on our website ๐Ÿ˜Š
Still working on it ๐Ÿ˜Š
Download Telegram
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
Given a roman numeral, convert it to an integer.



Example 1:

Input: s = "III"
Output: 3
Explanation: III = 3.
Example 2:

Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.
Example 3:

Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.


Constraints:

1 <= s.length <= 15
s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
It is guaranteed that s is a valid roman numeral in the range [1, 3999].
both side coversion
Longest Common Prefix?
Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".



Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.


Constraints:

1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lowercase English letters.
Java Hyd Team
Photo
Best shot of the day ๐Ÿ‘ป
Java Hyd Team pinned ยซOne question for you all where is main method in these codes ?? And if not why notยป
One message for you all you will never see these codes with main method without main method you can't excute codes in normal IDE so these codes will only work on competitive coding platforms for normal IDE you can just copy logic n use methods n constructors
Java Hyd Team pinned ยซOne message for you all you will never see these codes with main method without main method you can't excute codes in normal IDE so these codes will only work on competitive coding platforms for normal IDE you can just copy logic n use methods n constructorsยป
// Thread synchronization


import java.util.*;
import java.lang.*;

public class Number{

static int x;
synchronized static void increment(){
x++;
}
}
class First extends Thread {
public void run(){
for(int i= 1 ; i<= 100000 ; i++){
Number.increment();
}
}
}
class Second extends Thread{
public void run(){
for(int i= 1 ; i<= 100000 ; i++){
Number.increment();
}
}
}
class Synchronization{
public static void main(String[] args) {
First f = new First();
Second s = new Second();
f.start ();
s.start();
try{
f.join();
s.join();
} catch (Exception e ){
}
System.out.println("Final x value " + Number.x);
}
// creating threads using runnable interface

//runnable interface has only one specification called run()
// we can't start runnable object directly
// we can create the thread object by passing runnable object as parameter
// we can execute the thread logic by starting thread '

public class Main {
public static void main(String[] args) {
First f = new First ();
// f.start (); error
Thread t = new Thread (f);
t.start();
}
}
class First implements Runnable {
public void run(){
System.out.print("thread logic ");
}
}
๐Ÿ‘1
//Find sum of n numbers through threading ...


import java.util.*;
public class Defaults {
static int n ;
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.print("Sum of N numbers ");
System.out.print("Enter N number ");
n = x.nextInt();
Calculation Thread = new Calculation();
Thread.start();
try{
Thread.join();}
catch(Exception e ){}
System.out.print("Sum "+Calculation.sum);
}
}
class Calculation extends Thread{
static int sum =0;
public void run(){
System.out.print("Calc Started ");
for(int i = 1 ; i<= Defaults.n ; i++){
Calculation.sum= Calculation.sum+i;
}
System.out.print("Calc ends ");
}
}
import java.util.*;

class Employee{
int id ;
double Salary;
String name;
Employee (int id , String name , double Salary){
this .id = id;
this.name= name;
this.Salary= Salary;
}}
public class Main{
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
List<Employee> list = new Arraylist<Employee> ();
while (true){
System.out.print("1. Append \n 2. Display Record \n 3. Display All Record \n 4. Update \n 5. Delete \n 6. Exit");
if (ch == 1){
System.out.print(" Enter details");
int id = x.nextInt();
String name = x.next();
double Salary = x.nextDouble();
Employee e = new Employee (id, name, Salary);
list.add(e);
System.out.print("Record added");
}
else if (ch== 2){
if(list.isEmpty()){
System.out.print("Empty list ");
}
else
{
System.out.print("Details");
for(Employee e : list){
System.out.print(e.id + e.name + e.Salary);
}
}
System.out.print("Enter id");
int id = x.nextInt();
boolean found = false ;
for (Enployee e : list){
if ( e.id == id ){
System.out.print(e.name + e.Salary);
found = true ;
break ;
}
}if ( ! found )
System.out.print("invalid Id");
}

else if (ch== 3){
if ( list.isEmpty()){
System.out.print("Empty list");
}else{
System.out.print("Details");
for(employee e : list)
System.out.print(e.id+ e.name + e.Salary );
}
} else if (ch== 4){
if ( list.isEmpty()){
System.out.print("Empty list");
}else{
System.out.print("Enter Id");
int id = x.nextInt();
boolean found = false;
for(employee e : list)
{
if (e.id == id)
System.out.print("Enter salary to update ");
double Salary = x.nextDouble();
e.Salary = Salary;
System.out.print("Updated");
found = true ;
}
}
Q1
Solve the errors
/**
* Returns a string representation of the object.
* @apiNote
* In general, the
* {@code toString} method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read.
* It is recommended that all subclasses override this method.
* The string output is not necessarily stable over time or across
* JVM invocations.
* @implSpec
* The {@code toString} method for class {@code Object}
* returns a string consisting of the name of the class of which the
* object is an instance, the at-sign character `{@code @}', and
* the unsigned hexadecimal representation of the hash code of the
* object. In other words, this method returns a string equal to the
* value of:
* <blockquote>
* <pre>
* getClass().getName() + '@' + Integer.toHexString(hashCode())
* </pre></blockquote>
*
* @return a string representation of the object.
*/
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.



Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.
Example 2:

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:

Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.


Constraints:

3 <= nums.length <= 3000
-105 <= nums[i] <= 105
Sorted the array to be able to use binary search O((N * log(N)). Picking two numbers O(N * N) and finding the third one by binary searching O(log(N)). Adding the sorted result to the set to make sure that the combination of 3 numbers is unique. Then returning the result.
Binary search compares the target value to the middle element of the array. It works only on a sorted set of elements.