Maximize Array Sum with Given Operation in C++

Narendra Kumar
Updated on 31-Dec-2019 11:38:48

194 Views

DescriptionThere is an array of (2 * n – 1) integers. We can change sign of exactly n elements in the array. In other words, we can select exactly n array elements, and multiply each of them by -1. Find the maximum sum of the array.ExampleIf input array is {-2, 100, -3} then we can obtain maximum changing sign of -2 and -3. After changing sign array becomes −{2, 100, 3} and maximum sum of this array is 105.AlgorithmCount negative numbersCalculate the sum of the array by taking absolute values of the numbers.Find the minimum number of the array by ... Read More

Setting Background Position Using CSS

AmitDiwan
Updated on 31-Dec-2019 10:46:14

80 Views

Background position is to set the beginning position of a background image. For this, use the background-position property.ExampleLet us now see an example − Live Demo body {    background-image: url("https://www.tutorialspoint.com/images/Swift.png");    background-repeat: no-repeat;    background-attachment: fixed;    color: blue;    background-position: left center; } .demo {    text-decoration: overline underline; } Details Examination Center near ABC College. Exam begins at 9AM. OutputExampleLet us now see another example − Live Demo body {    background-image: url("https://www.tutorialspoint.com/images/Swift.png");    background-repeat: no-repeat;    background-attachment: fixed;    color: blue;    background-position: 50% 50%; } Details Examination Center near ABC College. Exam begins at 9AM. Output

Compare define vs const in PHP

Alok Prasad
Updated on 31-Dec-2019 10:10:49

5K+ Views

As we know both define() and const are used to declare a constant in PHP script.SyntaxLet's discuss the difference between these two.The basic difference between these two is that const defines constants at compile time, whereas define() defines them at run time.We can't use the const keyword to declare constant in conditional blocks, while with define() we can achieve that.const accepts a static scalar(number, string or other constants like true, false, null, __FILE__), whereas define() takes any expression.consts are always case sensitive, whereas define() allows you to define case insensitive constants by passing true as the third argument.const can also ... Read More

jQuery get() Method

AmitDiwan
Updated on 31-Dec-2019 09:33:09

155 Views

The get() method in jQuery is used to get the DOM elements matched by the selector.SyntaxThe syntax is as follows −$(selector).get(index)Above, the index specifies which of the matching elements to get.Let us now see an example to implement the jQuery get() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          var res = $("li").get(2);          $("span").text(res.innerHTML);       });    }); Devices TV Laptop Headphone Earphone SSD 3rd li element OutputThis will produce the following output −Now, click on the button −ExampleLet ... Read More

jQuery each() Method

AmitDiwan
Updated on 31-Dec-2019 09:29:42

206 Views

The each() method in jQuery is used to execute a function for each matched element.SyntaxThe syntax is as follows −$(selector).each(function(index, ele))Above, the index is the position of the selector, whereas ele is the current element.Let us now see an example to implement the jQuery each() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          $("li").each(function(){             alert($(this).text())          });       });    }); Devices TV Laptop Headphone Earphone SSD Get each element OutputThis will produce the ... Read More

Comparison Between AND and && Operator in PHP

Alok Prasad
Updated on 31-Dec-2019 09:28:32

572 Views

PHP offers incredible operators to perform operations such as arithmetic, assignment, comparison and many more ...In this article, more importance will be laid on logical operators "&&" and "AND" and will study how they can be utilized based on their precedence. Logical operators "&&" and "AND" produce true-or-false as results, and therefore these are also known as Boolean operators. Before diving into deep let's learn what is "AND" operator? "AND" operator returns true if and only if both the conditions are true. Let's take an example to demonstrate "AND" operator.ExampleOutput:TrueExplanation:Since variable $val1 = 20 and $val2 = 50, the condition $val1 ... Read More

jQuery Length Property

AmitDiwan
Updated on 31-Dec-2019 09:25:52

366 Views

The length property in jQuery is used to get the number of elements in the jQuery object.SyntaxThe syntax is as follows −$(selector).lengthExampleLet us now see an example to implement the jQuery length property − Live Demo    $(document).ready(function(){       $("button").click(function(){          document.getElementById("demo").innerHTML = "Count = " + $("li").length       });    }); Devices TV Laptop Headphone Earphone SSD Count of li OutputThis will produce the following output −Click “Count of li” to get the number of li elements −

jQuery Traversing Ancestors

AmitDiwan
Updated on 31-Dec-2019 09:23:39

295 Views

To traverse and find ancestors of an element, jQuery has the following methods: parent(), parents() and parentsUntil()−parent() methodThe parent() method in jQuery is used to return the direct parent element of the selected element. Let us see an example −Example Live Demo div {    width:600px; } .demo * {    display: block;    border: 2px solid yellow;    color: blue;    padding: 10px;    margin: 10px; }    $(document).ready(function(){       $("span").parent().css({"color": "blue", "border": "3px dashed blue"});    }); great-great-grandparent great-grandparent grandparent parent span OutputThis will produce ... Read More

jQuery toArray Method

AmitDiwan
Updated on 31-Dec-2019 09:14:34

167 Views

The toArray() method in jQuery is used to get all the DOM elements contained in the jQuery set, as an arraySyntaxThe syntax is as follows −$(selector).toArray()Let us now see an example to implement the jQuery toArray() method −Example Live Demo    $(document).ready(function(){       $("button").click(function(){          var arr = $("p").toArray()          for (var k = 0; i< arr.length; k++) {             alert(arr[k].innerHTML);          }       });    }); Devices This is demo text 1. This is demo text ... Read More

jQuery is() Method

AmitDiwan
Updated on 31-Dec-2019 09:11:50

335 Views

The is() method in jQuery is used to check whether one of the selected elements matches the value in parameter selectorEle.SyntaxThe syntax is as follows −$(selector).is(selectorElement, func(index, element))Above, selectorEle is a selector expression, element or jQuery object to match with the current set of the element. The func parameter is used to specify a function to run for the group of selected elements.ExampleLet us now see an example to implement the jQuery is() method − Live Demo div {    width:600px; } .demo * {    display: block;    border: 2px solid yellow;    color: blue;    padding: ... Read More

Advertisements