rizwan.amd
BAN USER
- 0of 0 votes
AnswersSay there are 3 array lists l1, l2 & l3 of same length. Thress threads accessing three lists. Say T1 -> l1, T2 ->l2 & T3 ->l3. It should print in the order say first element of 1st then first element of 2nd list and then first element of 3rd list. Then second element of 1st then second element of 2nd list and then second element of 3rd list.
- rizwan.amd in India| Report Duplicate | Flag | PURGE
Novell Tech Lead Threads - 0of 0 votes
AnswersRemove duplicates from an array say {1,2,7, 9, 9, 5, 4, 9} and create a new array and put the values in the new array. Note: Not to use any collection classes. Space and time complexity needs to be considered.
- rizwan.amd in India| Report Duplicate | Flag | PURGE
United HealthGroup Tech Lead Java
Name the balls as 1,2,3,4,5,6,7,8
Pick first 6 (or any 6) balls and put on either side of balance
Case 1:
If it matches then take remaining to balls say 7 and 8 and put on either side. Now which ever is heavier is the one
Case 2:
If first 6 does not match, then take the 3 balls from heavier side and pick any 2 of them and weigh it.
Case A:
If not same then the heavier is one.
Case B:
If same then the remaining 3rd ball is the heavier one
Name the balls as 1,2,3,4,5,6,7,8
Pick first 6 (or any 6) balls and put on either side of balance
Case 1:
If it matches then take remaining to balls say 7 and 8 and put on either side.
Now which ever is heavier is the one
Case 2:
If first 6 does not match, then take the 3 balls from heavier side and pick any 2 of them and weigh it.
Case A:
If not same then the heavier is one.
Case B:
If same then the remaining 3rd ball is the heavier one
private void reverseString(String strValue) {
List<String> lstWords = Arrays.asList(strValue.split(" "));
Collections.reverse(lstWords);
System.out.println(lstWords.toString().replaceAll(",", "").
replace("[", "").replace("]", ""));
}
private void reverseString(String strValue) {
List<String> lstWords = Arrays.asList(strValue.split(" "));
Collections.reverse(lstWords);
System.out.println(lstWords.toString().replaceAll(",", "").
replace("[", "").replace("]", ""));
}
private static void uniqueElements() {
List<Integer> lstA1 = Arrays.asList(1, 3, 4, 6 , 8, 10, 17, 34);
List<Integer> lstA2 = Arrays.asList(2, 8, 17, 33, 44, 66, 89, 100, 123);
Set<Integer> stResult = new TreeSet<Integer>();
for (int i : lstA1) {
if(!lstA2.contains(i)) stResult.add(i);
}
for (int i : lstA2) {
if(!lstA1.contains(i)) stResult.add(i);
}
System.out.println(stResult);
}
public class SingletonExample {
/** Instance variable */
private static SingletonExample m_objSingle = null;
/**
* Private constructor. Not to access from other classes
*/
private SingletonExample() {}
/**
* Method to return singleton object if the instance is null
* Otherwise return the same instance.
* synchronized block is used in case of multithreading
* @return {@link SingletonExample}
*/
public SingletonExample getInstance(){
synchronized (m_objSingle) {
if(null == m_objSingle) return new SingletonExample();
else return m_objSingle;
}
}
}
public long sumFromArray(int iNoOfIterations, int [] arrValues) {
long lSum = 0;
if(iNoOfIterations >= arrValues.length || iNoOfIterations < 0) return -1L;
if(iNoOfIterations == 0) for(int i = 0; i < arrValues.length; i++) lSum += arrValues[i];
else {
int iToCalc = 1;
while (iToCalc <= iNoOfIterations) {
int [] newArray = new int[arrValues.length - 1];
for(int i = 0; i < arrValues.length; i++) {
newArray[i] = (arrValues[i + 1] - arrValues[i]);
if(iToCalc == iNoOfIterations) lSum += newArray[i];
if( (i + 1) == arrValues.length - 1 ) break;
}
arrValues = newArray;
iToCalc++;
}
}
return lSum;
}
We need to use class loader to instantiate the class. Class.forName internally uses class loader. Not sure if this helps...
- rizwan.amd March 27, 2013Thank You
- rizwan.amd March 27, 2013public int maxOccurance(String strValue) {
char [] arrCh = strValue.toCharArray();
Map<String, Integer> mpCharCount = new HashMap<String, Integer>();
int iMaxValue = 0;
for (char cValue : arrCh) {
String strEachValue = String.valueOf(cValue);
int iCount = mpCharCount.containsKey(strEachValue) ? (mpCharCount.get(strEachValue) + 1) : 1;
mpCharCount.put(strEachValue, iCount);
if(iMaxValue < iCount) iMaxValue = iCount;
}
return iMaxValue;
}
We need to use multi threaded environment here
- rizwan.amd March 27, 2013We need to use multi threaded environment here
- rizwan.amd March 27, 2013
- rizwan.amd May 17, 2013