1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
What is the next line?
Answer
LZ algorithm
Next line is pairs (count, digit) for sequence of digits in previous line.
3 1 2 2 1 1
1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
What is the next line?
Answer
LZ algorithm
Next line is pairs (count, digit) for sequence of digits in previous line.
3 1 2 2 1 1
str = '1234'
str - '0' = [1 2 3 4]
When you use arithmetic operators with strings, strings is cast as doubles, which converts a string to ascii values,
Thus, subtraction will work just fine, though addition will give weird results
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently.
Constraint: Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to see which one is bigger/smaller.
Other way of asking this problem is, given a box with locks and keys where one lock can be opened by one key in the box. We need to match the pair.
Logic
As we apply partitioning on nuts and bolts both so the total time complexity will be Θ(2*nlogn) = Θ(nlogn) on average.
CODE
private static void matchPairs(char[] nuts, char[] bolts, int low, int high) { if (low < high) { // Choose last character of bolts array for nuts partition. int pivot = partition(nuts, low, high, bolts[high]); // Now using the partition of nuts choose that for bolts partition(bolts, low, high, nuts[pivot]); // Recur for [low...pivot-1] & [pivot+1...high] for nuts and bolts array. matchPairs(nuts, bolts, low, pivot-1); matchPairs(nuts, bolts, pivot+1, high); } }If you're only interested in the keys, you can iterate through the keySet() of the map:
Map<String, Object> map = ...;
for (String key : map.keySet()) {
// ...
}
If you only need the values, use values():
for (Object value : map.values()) {
// ...
}
Finally, if you want both the key and value, use entrySet():
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// ...
}
N<<3 gives 8n and subtract by n to get 7n
Each n bit shift will multibly by (2 ^ n)
((n<<3) - n) // works for positive number only
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
Software development life cycle model phases:
SDLC models:
First Process Model. Each phase must be completed before proceeding to the next phase without any overlapping in the phases.
Some situations where it is most appropriate:
Disadvantage
Whole requirement is divided into various builds. During each iteration, the development module goes through the requirements, design, implementation and testing phases. Each subsequent release of the module adds function to the previous release.
Some situations where it is most appropriate:
Disadvantage
Combination of iterative development process model and sequential linear development model i.e. waterfall model with very high emphasis on risk analysis.
The spiral model has four phases.
Uses of Spiral model:
Disadvantage
Complex management as there is a risk of running the spiral in indefinite loop. Not suitable for small or low risk projects as its expensive.
Extension of the waterfall model and is based on association of a testing phase for each corresponding development stage. There are Verification phases on one side and Validation phases on the other side with Coding phase in between.
Verification phases are:
Validation phases in V-Model:
Uses:
Disadvantage
Not a good model for long and complex and object-oriented projects. No working software is produced until late during the life cycle.
Focusing all the possible resources in software development and coding, with very little or no planning. Ideal for small projects
Advantages
Disadvantages
Breaks the product into small incremental builds which are provided in iterations. Each iteration lasts about 1-3 weeks and involves cross functional teams working simultaneously on various areas like planning, requirements analysis, design, coding, unit testing and acceptance testing.
Iterative approach is taken and working software build is delivered after each iteration. Each build is incremental in terms of features; the final build holds all the features required by the customer.
The most popular agile methods include Rational Unified Process (1994), Scrum (1995), Extreme Programming (1996), Adaptive Software Development and Dynamic Systems Development Method (DSDM) (1995).
Disadvantages
Different types of software prototypes: