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 ;
}
}
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 ;
}
}
/**
* 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.
*/
* 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
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.
When the binary search is used to perform operations on a sorted set, the number of iterations can always be reduced on the basis of the value that is being searched. You can see in the above snapshot of finding the mid element. The analogy of binary search is to use the information that the array is sorted and reduce the time complexity to O(log n).
This media is not supported in your browser
VIEW IN TELEGRAM
When you are out of social life for more than a year
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example 1:
Input: digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2:
Input: digits = ""
Output: []
Example 3:
Input: digits = "2"
Output: ["a","b","c"]
Constraints:
0 <= digits.length <= 4
digits[i] is a digit in the range ['2', '9'].
A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example 1:
Input: digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2:
Input: digits = ""
Output: []
Example 3:
Input: digits = "2"
Output: ["a","b","c"]
Constraints:
0 <= digits.length <= 4
digits[i] is a digit in the range ['2', '9'].