Ghosh
BAN USER- 0of 0 votes
AnswersI have one output as bellow:
- Ghosh in India
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
abc 202:0 0 7.9G 0 disk
`-xvda1 202:1 0 7.6G 0 part /
efg 202:16 0 54.2G 0 disk /mnt/
ijk 202:32 0 75.2G 0 disk
Now I want to get only those name which does not have any mount point. i.e., I want output as bellow:
abc
ijk
How can i achieve this using bash script?| Report Duplicate | Flag | PURGE
Akamai shell scripting - 0of 0 votes
AnswersDesign a system java same as relational database.
For example,
You Have employee table as bellow:ID | Name | Manager | Salary
Now you can execute queries like :
select * from Employee where ID= ' something' select * from Employee where Name= ' something' select * from Employee where salary = ' something'
In same way you have a class Emplyee as bellow:
class Employee { String ID; String Name; String Salary; String Manager; }
Now I want to query on this class as same as the sql queries above,
- Ghosh in India
How can I do it efficiently?
The code should be optimized on time complexity and space complexity.| Report Duplicate | Flag | PURGE
Oracle Software Architect Algorithm Data Structures Java Object Oriented Design - 0of 0 votes
AnswersSuppose you have a telephone directory. There You have telephone number and names. Names can be duplicate but telephone number will be unique, No use some datastructure in such a way that when we give telephone number it will return the corrosponding name, Again when we give a name, it will retrieve all the entries with same name and their corresponding telephone number from the datastructure. Complexity should be minimum as much as possible. I gave a solution of O(n) for the second case, but they did'nt agree this to be optimised.
- Ghosh in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm
- 0 Answers Java Memory Model and Synchronization
How Java Memory Model handles code reordering when synchronized keyword is used?
- Ghosh September 21, 2013
(I told that as per java specification code reorder should not happen, but he was asking more clear picture like is it possible to reorder inside the synchronized block or can not reorder with respect of out of synchronized block.)| Flag | PURGE
public static void sortArray(String productCodeArray[]){
System.out.println(Arrays.toString(productCodeArray));
int mid=0;
int low=0;
int high = productCodeArray.length-1;
while(mid<=high){
int priorityCode = getPriority(productCodeArray[mid]);
String tmp = null;
switch(priorityCode){
case 1:
tmp = productCodeArray[mid];
productCodeArray[mid] = productCodeArray[low];
productCodeArray[low]=tmp;
mid++;
low++;
break;
case 2:
mid++;
break;
case 3:
tmp = productCodeArray[mid];
productCodeArray[mid] = productCodeArray[high];
productCodeArray[high]=tmp;
high--;
break;
}
}
System.out.println("After Sorting: "+Arrays.toString(productCodeArray));
}
public static void main(String args[])
{
int array[]={2,4,3,5,6};
int multi=1;
for(int i=0;i<array.length;i++)
{
multi=multi*array[i];
}
System.out.println("multi: "+multi);
for(int i=0;i<array.length;i++)
{
array[i]=multi/array[i];
}
for(int i:array)
{
System.out.print(i+" ");
}
}
//chek for leftside as increasing
while(low<mid)
{
if((low-1)>=0 && array[low-1]>array[low])
{
low=low-1;
}
if((low+1)<=mid && array[low]<array[low+1])
{
low++;
}
else
{
int tmp=array[low];
array[low]=array[low+1];
array[low+1]=tmp;
}
}
Hope this will solve the problem.
- Ghosh February 09, 2015public static void main(String args[])
{
int array[]={1,2,3,5,3,6,1};
int low=0;
int high=array.length-1;
int mid=(low+high)/2;
int maxpos=-1;
int max=-1;
for(int i=0;i<array.length;i++)
{
if(array[i]>max)
{
max=array[i];
maxpos=i;
}
}
if(array[mid]!=max)
{
int temp=array[mid];
array[mid]=array[maxpos];
array[maxpos]=temp;
}
if(array[mid]==max)
{
//chek for leftside as increasing
while(low<mid)
{
if((low+1)<=mid && array[low]<array[low+1])
{
low++;
}
else
{
int tmp=array[low];
array[low]=array[low+1];
array[low+1]=tmp;
}
}
while((mid)<high)
{
if((mid+1)<=high && array[mid]>array[mid+1])
{
mid++;
}
else if(mid+1<=high)
{
int tmp=array[mid];
array[mid]=array[mid+1];
array[mid+1]=tmp;
}
}
//check for rightside as decreasing
}
for(int i:array)
{
System.out.print(i+" ");
}
}
Time Complexity: O(n)
- Ghosh February 08, 2015public static boolean isNumber(String str)
{
char[] charArray=str.toCharArray(); /*in java internally String is maintained as charecter
array, so atleast we have to use this function*/
char strt='0';
char end='9';
for(char ch: charArray)
{
if(ch<strt || ch> end)
return false;
}
return true;
}
Simple answer is it will never be thread safe if it is only static. Because static variables make sure that only one copy will be shared by all objects of that class, thats why static variable belongs to class. But it never says that static variables and methods will be thread safe. To make it thread safe, you have to use synchronize keyword over the Class object for that class.
- Ghosh September 13, 2014Here I have assumed that any rank can be the key for searching. So, First I have created a Key abstract class and GKey, RKey CKey and FKey classes for 4 types of rank Then I have Created a person class and have used those 4 types of key as member variable. The codes are given bellow.:
public abstract class Key {
int rank;
public Key(int rank) {
this.rank=rank;
}
public int getRank() {
return rank;
}
@Override
public String toString() {
return rank+" ";
}
}
Bellow The concrete classes of key:
public final class CKey extends Key {
final int c_key;
public CKey(int c_key) {
super(c_key);
this.c_key=c_key;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + c_key;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CKey other = (CKey) obj;
if (c_key != other.c_key)
return false;
return true;
}
}
In same way we shall implement CKey, GKey, FKey and RKey.
Now the person class will be like bellow:
public class Person {
String name;
String number;
String address;
Key g_rank;
Key r_rank;
Key c_rank;
Key f_rank;
public Person(String name, String number, String address, int g_rank, int c_rank, int r_rank, int f_rank ) {
this.name=name;
this.number=number;
this.address=address;
this.g_rank=new GKey(g_rank);
this.r_rank=new RKey(r_rank);
this.c_rank=new CKey(c_rank);
this.f_rank=new FKey(f_rank);
}
public String getAddress() {
return address;
}
public int getC_rank() {
return c_rank.getRank();
}
public int getF_rank() {
return f_rank.getRank();
}
public int getG_rank() {
return g_rank.getRank();
}
public String getName() {
return name;
}
public String getNumber() {
return number;
}
public int getR_rank() {
return r_rank.getRank();
}
public void setAddress(String address) {
this.address = address;
}
public void setC_rank(int c_rank) {
this.c_rank = new CKey(c_rank);
}
public void setF_rank(int f_rank) {
this.f_rank = new FKey(f_rank);
}
public void setG_rank(int g_rank) {
this.g_rank = new GKey(g_rank);
}
public void setName(String name) {
this.name = name;
}
public void setNumber(String number) {
this.number = number;
}
public void setR_rank(int r_rank) {
this.r_rank = new RKey(r_rank);
}
@Override
public String toString() {
return name+" "+number+" "+address+" "+g_rank+" "+r_rank+" "+c_rank+" "+f_rank;
}
}
Then we are having organization class that will use person class:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Organization {
Map<String,Person> personList=new HashMap<String, Person>();
HashMap<Key, List<String>> rankList= new HashMap<Key, List<String>>();
public Organization() {
// TODO Auto-generated constructor stub
}
private void insert(Key key, Person p)
{
if(!rankList.containsKey(key))
{
ArrayList<String> personNumberList= new ArrayList<String>();
personNumberList.add(p.getNumber());
rankList.put(key, personNumberList);
}
else
{
List<String> temp= rankList.get(key);
temp.add(p.getNumber());
rankList.put(key, temp);
}
}
public void insert(Person p)
{
personList.put(p.getNumber(), p);
Key c_key=new CKey(p.getC_rank());
insert(c_key, p);
Key f_key= new FKey(p.getF_rank());
insert(f_key, p);
Key r_key= new RKey(p.getR_rank());
insert(r_key, p);
Key g_key= new GKey(p.getG_rank());
insert(g_key, p);
}
public List<Person> retrieve(Key key)
{
System.out.println(key);
List<String> numberList=rankList.get(key);
System.out.println(numberList);
List<Person> personL=new ArrayList<Person>();
for(String number:numberList)
{
personL.add(personList.get(number));
}
return personL;
}
//this part is to retrieve person based on key
class MyComparator implements java.util.Comparator<Person>
{
Class keytype;
public MyComparator() {
// TODO Auto-generated constructor stub
}
public MyComparator(Class keyType) {
this.keytype=keyType;
}
@Override
public int compare(Person o1, Person o2) {
if(keytype == GKey.class)
{
return o1.getG_rank()-o2.getG_rank();
}
else if(keytype==CKey.class)
{
return o1.getC_rank()-o2.getC_rank();
}
else if(keytype==FKey.class)
{
return o1.getF_rank()-o2.getF_rank();
}
else
{
return o1.getR_rank()-o2.getR_rank();
}
}
}
public List<Person> retrievetop(Class keyType)
{
List<Person> personL= new ArrayList<Person>(personList.values());
Collections.sort(personL,new MyComparator(keyType));
return personL;
}
}
And finally we have Test class to test the whole thing:
import java.util.List;
public class Test {
public static void main(String args[])
{
Organization org= new Organization();
org.insert(new Person("abcd", "a001", "abcd", 101, 101, 4, 7));
org.insert(new Person("abcd1", "a002", "abcd1", 121, 101, 41, 71));
org.insert(new Person("abcd2", "a003", "abcd2", 101, 102, 42, 72));
org.insert(new Person("abcd3", "a004", "abcd3", 123, 103, 43, 73));
org.insert(new Person("abcd4", "a005", "abcd4", 124, 104, 44, 74));
Key key= new CKey(101);
List<Person> person= org.retrieve(key);
System.out.println(person);
//this part is to get sorted list of person based on a key
List<Person>personL=org.retrievetop(GKey.class);
System.out.println("name number address g_rank c_rank r_rank f_rank");
for(Person p: personL)
{
System.out.println(p);
}
}
}
Here is a solution with o(n) time complexity. Please correct me if I am making any mistake in complexity calculation.
public static void main(String[] args) {
String s="abdecadcbdaeaec";
class StringHolder
{
private String s="";
public StringHolder(char c) {
this.s=this.s+c;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public void addAnother()
{
this.s=this.s+s.charAt(0);
}
}
Map<Character, StringHolder> alphaMap=new LinkedHashMap<>();
for(char c:s.toCharArray())
{
if(!alphaMap.containsKey(c))
{
alphaMap.put(c, new StringHolder(c));
}
else
{
alphaMap.get(c).addAnother();
}
}
String result="";
for(char c:alphaMap.keySet())
{
result=result+alphaMap.get(c).getS();
}
System.out.print(result);
}
public static void main(String[] args) {
String str= "a13b2c14d15";
Map<Character, Integer> alphaMap= new LinkedHashMap<>();
int count=0;
char hold='\0';
boolean flag=false;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)<'0'||str.charAt(i)>'9')
{
flag=true;
count=0;
hold=str.charAt(i);
}
else
{
count=count*10+(str.charAt(i)-48);
}
if(flag)
{
alphaMap.put(hold, count);
}
}
System.out.println(alphaMap);
Set<Character> charSet= alphaMap.keySet();
for(char c:charSet)
{
for(int i=0;i<alphaMap.get(c);i++)
{
System.out.print(c);
}
}
}
public String countCharecter(String str)
{
HashMap<Character, Integer> map= new HashMap<Character,Integer>();
ArrayList<Character> arryList=new ArrayList<Character>();
for(char c:str.toCharArray())
{
if(!arryList.contains(c))
arryList.add(c);
if(map.containsKey(c))
{
int i=map.get(c);
map.put(c, ++i);
}
else
map.put(c, 1);
}
str="";
for(int i=0;i<arryList.size();i++)
{
str=str+map.get(arryList.get(i))+arryList.get(i);
}
return str;
}
Repchristinetcollazoc, Software Analyst
I am a pediatric nurse.I administer directly procedures and medicines to children according to prescribed I also continually assess ...
RepMarryJohan, Consultant at ASAPInfosystemsPvtLtd
I am successfully manage and coordinate graphic design projects from concept through completion. Create and conduct highly persuasive sales and ...
Repjoycejflora, Android Engineer at ABC TECH SUPPORT
I am excited about cooperation and interesting projects. Last year I work for a person who provides the black magic ...
Repmelodyakeel, Consultant at Progress
Hello I am Melody. I am working as Human resource clerks, also called human resource assistants. I can maintain employee ...
Reppamelajoung, Dev Lead at Absolute Softech Ltd
I have worked as a wedding photographer for the past two years, first as a photographer’s assistant and then ...
Repmarthajpatton, Data Scientist at AppPerfect
Managed a small team implementing gravy in Prescott, AZ. Developed several new methods for easy break up spells.Had some ...
Repthubmorfin, Android Engineer at ABC TECH SUPPORT
I am currently working as a safety-focused Service Technician from Red Bank. I execute routine maintenance work while advising clients ...
RepBlakeRileyHomes, Analyst at Aristocrat Gaming
Blake Riley Homes is the leading interior designing and real estate home staging Orange County CA company.Our professional designs ...
RepShirleyCWest, Software Engineer at Agilent Technologies
Hello, me Shirley and I from Savage. I am an artist and I love to doing art and I am ...
Repjonej8821, Blockchain Developer at Alliance Global Servies
I am EbonyTuckson .I am a teacher who works in High school. I work during school hours but may also ...
Repharoldknopph, Android test engineer at AMD
I am a publicity writer from Atlanta USA . I create an intended public image for individuals, groups, or organizations. I ...
- Ghosh April 17, 2020