code-rag-bench/online-tutorials huggingface dataset:
Tailwind CSS Background Image - GeeksforGeeks

23 Mar, 2022
This class accepts more than one value in tailwind CSS. All the properties are covered in class form. It is the alternative to the CSS background-image property. This class is used to set one or more background images to an element. By default, it places the image on the top left corner. To specify two or more images, separate the URLs with a comma.
Background Image classes:
bg-none: This class is used not to set any linear-gradient.
bg-gradient-to-t: This class is used to set the linear-gradient to the top.
bg-gradient-to-tr: This class is used to set the linear-gradient to the top right.
bg-gradient-to-r: This class is used to set the linear-gradient to right.
bg-gradient-to-br: This class is used to set the linear-gradient to the bottom right.
bg-gradient-to-b: This class is used to set the linear-gradient to the bottom.
bg-gradient-to-bl: This class is used to set the linear-gradient to the bottom left.
bg-gradient-to-l: This class is used to set the linear-gradient to left.
bg-gradient-to-tl: This class is used to set the linear-gradient to the top left.
Syntax:
<element class="bg-gradient-to-{direction}">...</element>
Example:
HTML
<!DOCTYPE html> <html> <head>     <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"    rel="stylesheet"> </head>   <body class="text-center">     <h1 class="text-green-600 text-5xl font-bold">     GeeksforGeeks     </h1>     <b>Tailwind CSS Background Image Class</b>     <div class="mx-4 grid grid-cols-3 gap-2">    <div class="h-12 w-full bg-gradient-to-r rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-tr rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-br rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-b rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-bl rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-tl rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div>    <div class="h-12 w-full bg-gradient-to-l rounded-lg                from-yellow-400 via-green-500 to-blue-500">    </div></body> </html>
Output:
Tailwind CSS background image
Tailwind CSS
Tailwind-Background
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to update Node.js and NPM to next version ?
How to create footer to stay at the bottom of a Web page?
How to apply style to parent if it has child with CSS?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
How to Pass Image as a parameter in JavaScript function ? - GeeksforGeeks

01 Sep, 2020
We all are familiar with functions and its parameters and we often use strings, integers, objects, arrays as a parameter in JavaScript functions but now will see how to pass an image as a parameter in JavaScript function. We will use vanilla JavaScript here.
First, create a function that receives a parameter then calls that function. The parameter should be a string that refers to the location of the image.
Syntax:
function displayImage (picUrl) {
    ...
}

displayImage('/assets/myPicture.jpg')

Example: In this example, we will display an image inside a DIV whose id is “imgDiv”.
<div id="imgDiv">
    <!-- Here we show the picture -->
</div>

Steps:
First, create a markup that has an h1 and a div tag whose id is imgDiv in which we are going to insert the image.Create a script tag in which we all are going to make all our logics.Create a variable named divLocation and assign the DOM element of that div into the variable.Now create an img element with document.createElement() and assign it into variable imgElement.Then assign the URL of the image to its href attribute by using imgElement.href = /image location/.Now append the img Element to the div element by append() method.
First, create a markup that has an h1 and a div tag whose id is imgDiv in which we are going to insert the image.
Create a script tag in which we all are going to make all our logics.
Create a variable named divLocation and assign the DOM element of that div into the variable.
Now create an img element with document.createElement() and assign it into variable imgElement.
Then assign the URL of the image to its href attribute by using imgElement.href = /image location/.
Now append the img Element to the div element by append() method.
<!DOCTYPE html><html>  <body>    <center>        <h1>Hello GFG</h1>        <div id="imgDiv"></div>    </center>      <script>        var Pic = ""          function displayImage(pic) {            let divLocation = document.getElementById("imgDiv");            let imgElement = document.createElement("img");            imgElement.src = pic            divLocation.append(imgElement);        }          Pic = "https://write.geeksforgeeks.org/static/media/Group%20210.08204759.svg";          displayImage(Pic);    </script></body>  </html>
Output:
HTML-Misc
JavaScript-Misc
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
ASP Redirect Method - GeeksforGeeks

19 Aug, 2020
The ASP Redirect Method is used to redirect the client to a different URL. It is a predefined method of the Response Object.
Syntax:
Response.Redirect URL





Parameter Values: This method accepts a single parameter as mentioned above and described below:
URL: It defines a Uniform resource locator which represents the browser is redirected to.
Return value: This method does not return any value. 
Example: Below code redirects the user to geeksforgeeks website.
<%
Response.Redirect "https://www.GeelsforGeeks.org.in"
%>


ASP-Properties
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
How to create footer to stay at the bottom of a Web page?
Differences between Functional Components and Class Components in React
How to set the default value for an HTML <select> element ?
File uploading in React.js
How to set input type date in dd-mm-yyyy format using HTML ?
How to apply style to parent if it has child with CSS?
GATE | GATE-CS-2015 (Set 2) | Question 55 - GeeksforGeeks

28 Jun, 2021
Suppose you are provided with the following function declaration in the C programming language.
   int partition (int a[], int n); 
The function treats the first element of a[] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part. The following partially given function in the C programming language is used to find the kth smallest element in an array a[ ] of size n using the partition function. We assume k ≤ n
int kth_smallest (int a[], int n, int k){   int left_end = partition (a, n);   if (left_end+1==k)   {       return a [left_end];   }   if (left_end+1 > k)   {      return kth_smallest (____________________);   }   else   {      return kth_smallest (____________________);    }}
The missing argument lists are respectively(A) (a, left_end, k) and (a+left_end+1, n–left_end–1, k–left_end–1)(B) (a, left_end, k) and (a, n–left_end–1, k–left_end–1)(C) (a, left_end+1, N–left_end–1, K–left_end–1) and(a, left_end, k)(D) (a, n–left_end–1, k–left_end–1) and (a, left_end, k)Answer: (A)Explanation: See method 4 of https://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array/Quiz of this Question
GATE-CS-2015 (Set 2)
GATE-GATE-CS-2015 (Set 2)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | Gate IT 2007 | Question 25
GATE | GATE-CS-2001 | Question 39
GATE | GATE-CS-2000 | Question 41
GATE | GATE-CS-2005 | Question 6
GATE | GATE MOCK 2017 | Question 21
GATE | GATE-CS-2006 | Question 47
GATE | GATE MOCK 2017 | Question 24
GATE | Gate IT 2008 | Question 43
GATE | GATE-CS-2009 | Question 38
GATE | GATE-CS-2003 | Question 90
Underscore.js _.functions() Function - GeeksforGeeks

25 Nov, 2021
The _.functions() function is used to return the sorted list of all methods that present in an object.
Syntax:
_.functions(object)
Parameters: This function accepts single parameter as mentioned above and described below:
object: It contains the object element that holds the elements [key, value] pair.
Return Value: It returns the sorted list of all methods that present in an object.
Example:
<!DOCTYPE html><html>  <head>    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">    </script></head>  <body>    <script type="text/javascript">          console.log(_.functions(_));    </script></body>  </html>
Output:
JavaScript - Underscore.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to calculate the number of days between two dates in javascript?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Python - Media object in Tweepy - GeeksforGeeks

21 Jun, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
The Media object in Tweepy module contains the information about a media file uploaded on Twitter.
Here are the list of attributes in the Media object :
media_id : The ID of the media object.
media_id_str : The ID of the media object as a string.
size : The size of the media object in bytes.
expires_after_secs : The time in seconds after which the media object expires.
image_type : The type of image.
w : The width of the media object.
h : The height of the media object.
Example : We will use media_upload() method to upload and fetch the media object.
Consider the following image :
# import the moduleimport tweepy  # assign the values accordinglyconsumer_key = ""consumer_secret = ""access_token = ""access_token_secret = ""  # authorization of consumer key and consumer secretauth = tweepy.OAuthHandler(consumer_key, consumer_secret)  # set access to user's access key and access secret auth.set_access_token(access_token, access_token_secret)  # calling the api api = tweepy.API(auth)  # uploading the media and fetching the Media objectmedia = api.media_upload("gfg.png")  # printing the informationprint("The media_id is : " + str(media.media_id))print("The media_id_string is : " + media.media_id_string)print("The size is : " + str(media.size))print("The expires_after_secs is : " + str(media.expires_after_secs))print("The image_type is : " + str(media.image["image_type"]))print("The w is : " + str(media.image["w"]))print("The h is : " + str(media.image["h"]))
Output :
The media_id is : 1273526215773573121
The media_id_string is : 1273526215773573121
The size is : 3346
The expires_after_secs is : 86400
The image_type is : image/png
The w is : 225
The h is : 225

Python-Tweepy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Java - String compareTo() Method

This method compares this String to another Object.
Here is the syntax of this method −
int compareTo(Object o)

Here is the detail of parameters −
O − the Object to be compared.
O − the Object to be compared.
The value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
The value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
public class Test {

   public static void main(String args[]) {
      String str1 = "Strings are immutable";
      String str2 = new String("Strings are immutable");
      String str3 = new String("Integers are not immutable");
      
      int result = str1.compareTo( str2 );
      System.out.println(result);
      
      result = str2.compareTo( str3 );
      System.out.println(result);
   }
}
This will produce the following result −
0
10


    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
HTML <script> integrity Attribute - GeeksforGeeks

27 Sep, 2021
The integrity attribute is used to give permission to the Browser to check the fetched script to make ensure the source code is never loaded. It is used to check that whether the third party has been altered the resource or not. 
Subresource Integrity(SRI) is a security feature developed by w3comsortium which is used to give permission to a Browser to verify all the external scripts that would be fetched. It gives surety that the scripts are not altered by the third party. 
The working process of SRI is going to follow the steps: 
The webpage holds the hash value and on the other side, the server holds the .js file.
Now, the browser matches the hash value of the integrity attribute
In the end, if the value of hash matches then the file is used otherwise the file is blocked.
Syntax 
<script integrity="filehash">
 Attribute Values: 
filehash:It indicates the hash value of the external script file.
Example 1:   
HTML
<!DOCTYPE html><html> <head>    <title>        HTML script integrity Attribute    </title></head> <body style="text-align:center;">    <h1>        GeeksForGeeks    </h1>     <h2>        HTML script integrity Attribute    </h2>     <script id="myGeeks" type="text/javascript"        src="my_script.js"        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo">    </script>    <br>     <button>Submit</button></body> </html>
Output:
Example 2: 
HTML
<!DOCTYPE html><html> <head>    <title>        script tag    </title>     <style>        body {             text-align: center;        }         h1 {            color: green;        }    </style></head> <body>    <h1>GeeksforGeeks</h1>     <h2>        HTML integrity Attribute in <script> Element    </h2>    <p id="Geeks"></p>      <script charset="UTF-8" integrity="e0d123e5f316bef78bfdf5a008837577OOo_2.0.1_LinuxIntel_install.tar.gz">         document.getElementById("Geeks")            .innerHTML = "Hello GeeksforGeeks!";    </script></body> </html>
Output:
Supported Browsers: 
Google Chrome 45.0
Internet Explorer 17.0
Opera66.0
Apple safari 13.0
Firefox 43.0
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
simranarora5sos
HTML-Attributes
HTML-Tags
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
REST API (Introduction)
Design a web page using HTML and CSS
Form validation using jQuery
Angular File Upload
How to Dynamically Add/Remove Table Rows using jQuery ?
Installation of Node.js on Linux
Roadmap to Become a Web Developer in 2022
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
How to calculate the number of days between two dates in javascript?
How to Sort Words in Alphabetic Order using Python?

Assuming that the a string object contains multiple words separated by one space. The split() method of string class returns a list of words separated by space character. This list object is sorted by invoking sort() method of built-in list class
>>> string='Hello how are you?'
>>> list=string.split()
>>> list
['Hello', 'how', 'are', 'you?']
>>> list.sort()
>>> list
['Hello', 'are', 'how', 'you?']
Sum of Array Elements | Practice | GeeksforGeeks

Given an integer array arr of size n, you need to sum the elements of arr.
Example 1:
Input:
n = 3
arr[] = {3 2 1}
Output: 6
Example 2:
Input:
n = 4
arr[] = {1 2 3 4}
Output: 10

Your Task:
You need to complete the function sumElement() that takes arr and n and returns the sum. The printing is done by the driver code.
Expected Time Complexity: O(n).
Expected Auxiliary Space: O(1).
Constraints:
1 <= n <= 103
1 <= arri <= 104
0
adityadixit7054in 6 hours
Take a variable sum=0
then iterate the array and add to sum
then return sum
def sumElement(arr,n):   sum=0   for i in range(n):       sum=sum+arr[i]   return sum
0
mehtay0375 days ago
Python Solution:
def sumElement(arr,n):   #code here   return sum(arr) 
0
atif836145 days ago
JAVA SOLUTION
 if(n==0){
           return 0;
       }
       int sum=0;
       for(int i=0;i<n;i++){
           sum=sum+arr[i];
       }
       return sum;
0
rishabhchemistry36 days ago
 int res=0;   for(int i=0;i<n;i++){       res=res+arr[i];   }   return res;
0
zubairbinmasood786abcd1 week ago
C++ Recursion
if(n<0)
        return 0;
return arr[n - 1] + sumElement(arr,n - 1);
0
zubairbinmasood786abcd1 week ago
C++ One Liner : )
return accumulate(arr,arr + n,0);
0
diagovenk1 week ago
Hello guys. Four lines easy java solution
public static int sumElement(int arr[], int n)   {       // Your code here       int sum = 0;       for(int i=0; i<n; i++){           sum += arr[i];       }       return sum;   }
0
shaikhusama7453 weeks ago
C++ Code using Recursionint sumElement(int arr[],int n){   //Base Case   if( n == 0 ){       return 0;   }   if( n == 1 ){       return arr[0];   }
   //Recursive Call
      int remainingPart = sumElement(arr+1,n-1);   int sum = arr[0] + remainingPart;      return sum;} 
0
rapuriteja1 month ago
def sumElement(arr,n):   su = sum(arr)   return su
0
ravi119033851 month ago
//JAVA
int sum=0;       for(int i: arr)       {           sum+=i;       }       return sum;
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.
Find data for specific date in MongoDB?

Let’s say you have saved the Login date of users. Now, you want the count of records for specific date only i.e. login date. For this, use gteandlt operator along with count(). Let us first create a collection with documents −
> db.findDataByDateDemo.insertOne({"UserName":"John","UserLoginDate":new ISODate("2019-01-31")});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cdd8cd7bf3115999ed511ed")
}
> db.findDataByDateDemo.insertOne({"UserName":"Larry","UserLoginDate":new ISODate("2019-02-01")});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cdd8ce7bf3115999ed511ee")
}
> db.findDataByDateDemo.insertOne({"UserName":"Sam","UserLoginDate":new ISODate("2019-05-02")});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cdd8cf3bf3115999ed511ef")
}
> db.findDataByDateDemo.insertOne({"UserName":"David","UserLoginDate":new ISODate("2019-05-16")});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cdd8d00bf3115999ed511f0")
}
> db.findDataByDateDemo.insertOne({"UserName":"Carol","UserLoginDate":new ISODate("2019-10-19")});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cdd8d0ebf3115999ed511f1")
}
Following is the query to display all documents from a collection with the help of find() method −
> db.findDataByDateDemo.find();
This will produce the following output −
{ "_id" : ObjectId("5cdd8cd7bf3115999ed511ed"), "UserName" : "John", "UserLoginDate"  : ISODate("2019-01-31T00:00:00Z") }
{ "_id" : ObjectId("5cdd8ce7bf3115999ed511ee"), "UserName" : "Larry", "UserLoginDate" : ISODate("2019-02-01T00:00:00Z") }
{ "_id" : ObjectId("5cdd8cf3bf3115999ed511ef"), "UserName" : "Sam", "UserLoginDate"   : ISODate("2019-05-02T00:00:00Z") }
{ "_id" : ObjectId("5cdd8d00bf3115999ed511f0"), "UserName" : "David", "UserLoginDate" : ISODate("2019-05-16T00:00:00Z") }
{ "_id" : ObjectId("5cdd8d0ebf3115999ed511f1"), "UserName" : "Carol", "UserLoginDate" : ISODate("2019-10-19T00:00:00Z") }
Following is the query to find data for a specific date in MongoDB. Here, we are getting the users who logged in between specific dates −
> db.findDataByDateDemo.count({"UserLoginDate":{ "$gte": new Date("2019-05-02"), "$lt": new Date("2019-05-18") }});
This will produce the following output −
2
Merge Two Sorted Lists in Python

Suppose we have two sorted lists A and B. We have to merge them and form only one sorted list C. The size of lists may different.
For an example, suppose A = [1,2,4,7] and B = [1,3,4,5,6,8], then merged list C will be [1,1,2,3,4,4,5,6,7,8]
We will solve this using recursion. So the function will work like below −
Suppose the lists A and B of function merge()
if A is empty, then return B, if B is empty, then return A
if value in A <= value in B, then A.next = merge(A.next, B) and return A
otherwise, then B.next = merge(A, B.next) and return B
Let us see the implementation to get a better understanding
 Live Demo
class ListNode:
   def __init__(self, data, next = None):
      self.val = data
      self.next = next
   def make_list(elements):
      head = ListNode(elements[0])
      for element in elements[1:]:
         ptr = head
         while ptr.next:
            ptr = ptr.next
         ptr.next = ListNode(element)
      return head
def print_list(head):
   ptr = head
   print('[', end = "")
   while ptr:
      print(ptr.val, end = ", ")
      ptr = ptr.next
   print(']')
class Solution:
   def mergeTwoLists(self, l1, l2):
      """
      :type l1: ListNode
      :type l2: ListNode
      :rtype: ListNode
      """
      if not l1:
         return l2
      if not l2:
         return l1
      if(l1.val<=l2.val):
         l1.next = self.mergeTwoLists(l1.next,l2)
         return l1
      else:
         l2.next = self.mergeTwoLists(l1,l2.next)
         return l2
head1 = make_list([1,2,4,7])
head2 = make_list([1,3,4,5,6,8])
ob1 = Solution()
head3 = ob1.mergeTwoLists(head1,head2)
print_list(head3)
head1 = make_list([1,2,4,7])
head2 = make_list([1,3,4,5,6,8])
[1, 1, 2, 3, 4, 4, 5, 6, 7, 8, ]
Frog Jump in C++

Suppose there is a frog that is crossing a river. The river is divided into x units and at each unit there may be a stone. The frog can jump on a stone, but not water. Here we have a list of stones' positions in sorted ascending order sequence, we have to check whether the frog is able to cross the river by landing on the last stone, or not. Initially, the frog is on the first stone and assume the first jump must be of 1 unit.
When the frog's current jump was k units, then its next jump must be either k - 1, k, or k + 1 units. And frog can only jump in the forward direction.
So if the given array is like [0,1,3,4,5,7,9,10,12], then the answer will be true as, the frog can jump to the 1 unit to 2nd stone, 2 units to 3rd stone, then again 2 units to 4th stone, then 3 units to 6th stone, 4 units to 7th stone and finally 5 units to 8th stone.
To solve this, we will follow these steps −
Define a map called visited
Define a function canCross(), this will take an array stones, pos initialize it with 0, k initialize it with 0,
key := pos OR (left shift k 11 bits)
if key is present in the visited, then −return visited[key]
return visited[key]
for initialize i := pos + 1, when i < size of stones, update (increase i by 1), do −gap := stones[i] - stones[pos]if gap < k - 1, then −Ignore following part, skip to the next iterationif gap > k + 1, then −visited[key] := falsereturn falseif call the function canCross(stones, i, gap) is non-zero, then −visited[key] = truereturn true
gap := stones[i] - stones[pos]
if gap < k - 1, then −Ignore following part, skip to the next iteration
Ignore following part, skip to the next iteration
if gap > k + 1, then −visited[key] := falsereturn false
visited[key] := false
return false
if call the function canCross(stones, i, gap) is non-zero, then −visited[key] = truereturn true
visited[key] = true
return true
visited[key] = true when (pos is same as size of stones - 1) otherwise false
return visited[key]
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
class Solution {
public:
   unordered_map < lli, int > visited;
   bool canCross(vector<int>& stones, int pos = 0, int k = 0) {
      lli key = pos | k << 11;
      if(visited.find(key) != visited.end())return visited[key];
      for(int i = pos + 1; i < stones.size(); i++){
         int gap = stones[i] - stones[pos];
         if(gap < k - 1)continue;
         if(gap > k + 1){
            return visited[key] = false;
         }
         if(canCross(stones, i, gap))return visited[key] = true;
      }
      return visited[key] = (pos == stones.size() - 1);
   }
};
main(){
   Solution ob;
   vector<int> v = {0,1,3,5,6,8,12,17};
   cout << (ob.canCross(v));
}
0,1,3,5,6,8,12,17
1
How to generate a random BigInteger value in Java?

To generate random BigInteger in Java, let us first set a min and max value −
BigInteger maxLimit = new BigInteger("5000000000000");
BigInteger minLimit = new BigInteger("25000000000");
Now, subtract the min and max −
BigInteger bigInteger = maxLimit.subtract(minLimit);
Declare a Random object and find the length of the maxLimit:
Random randNum = new Random();
int len = maxLimit.bitLength();
Now, set a new B integer with the length and the random object created above.
 Live Demo
import java.math.BigInteger;
import java.util.Random;
public class Demo {
   public static void main(String[] args) {
      BigInteger maxLimit = new BigInteger("5000000000000");
      BigInteger minLimit = new BigInteger("25000000000");
      BigInteger bigInteger = maxLimit.subtract(minLimit);
      Random randNum = new Random();
      int len = maxLimit.bitLength();
      BigInteger res = new BigInteger(len, randNum);
      if (res.compareTo(minLimit) < 0)
         res = res.add(minLimit);
      if (res.compareTo(bigInteger) >= 0)
         res = res.mod(bigInteger).add(minLimit);
         System.out.println("The random BigInteger = "+res);
   }
}
The random BigInteger = 3874699348568
How to save Matplotlib 3d rotating plots?

To save Matplotlib 3d roatating plots, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create a new figure or activate an existing figure.
Add an '~.axes.Axes' to the figure as part of a subplot arrangement.
Return a tuple X, Y, Z with a test data set.
Plot a 3D wireframe.
Rotate the axis with an angle.
Redraw the current figure.
Run the GUI event loop for some seconds.
To display the figure, use show() method.
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.1)
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)

for angle in range(0, 360):
   ax.view_init(30, angle)
   plt.draw()
   plt.pause(.001)

plt.show()
Aggregation in Java

Aggregation refers to HAS-A relationship. Let’s look at the example first −
public class Vehicle{}
public class Speed{}
public class Van extends Vehicle {
   private Speed sp;
}
This shows that class Van HAS-A Speed. By having a separate class for Speed, we do not have to put the entire code that belongs to speed inside the Van class, which makes it possible to reuse the Speed class in multiple applications.
In the Object-Oriented feature, the users do not need to bother about which object is doing the real work. To achieve this, the Van class hides the implementation details from the users of the Van class. So, basically what happens is the users would ask the Van class to do a certain action and the Van class will either do the work by itself or ask another class to perform the action.This concept of containing an object to do action is termed as Aggregation.
Tryit Editor v3.7

Tryit: HTML formatting
How to remove underline for anchors tag using CSS? - GeeksforGeeks

08 Feb, 2019
The anchor tag is used to define the hyperlinks and it display underlined anchor part by default. The underline can be easily remove by using text-decoration property. The text-decoration property of CSS allows to decorate the text according to requirement. By setting the text-decoration to none to remove the underline from anchor tag.
Syntax:
text-decoration: none;
Example 1: This example sets the text-decoration property to none.
<!-- HTML code to remove underline    from anchor tag --><!DOCTYPE html> <html>   <head>     <title>         text-decoration property     </title>          <!-- text-decoration property to remove        underline from anchor tag -->    <style>        #GFG {            text-decoration: none;        }    </style></head>   <body style = "text-align:center;">       <h1 style = "color:green;" >         GeeksForGeeks     </h1>          <h3>Original Link</h3>          <a href = "#">Link 1</a>          <br>           <h3>removed Underline</h3>          <a id = "GFG" href = "#">Link 2</a> </body>   </html>                    
Output:
Example 2: Use hover property to remove underline when mouse move over the anchor part.
<!-- HTML code to remove underline    from anchor tag --><!DOCTYPE html> <html>   <head>     <title>         text-decoration property     </title>          <!-- text-decoration property to remove        underline from anchor tag -->    <style>        a:link {            text-decoration: underline;        }        a:hover {            text-decoration: none;        }    </style></head>   <body style = "text-align:center;">       <h1 style = "color:green;" >         GeeksforGeeks     </h1>          <a id = "GFG" href = "#">GeeksforGeeks Anchor Part</a> </body>   </html>                    
Output:Before Mouse move over:After Mouse move over:
Picked
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Front End Developer Skills That You Need in 2022
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
Convert a string to an integer in JavaScript
Differences between Functional Components and Class Components in React
File uploading in React.js
How to Open URL in New Tab using JavaScript ?
Types of CSS (Cascading Style Sheet)
How to Insert Form Data into Database using PHP ?
How to execute PHP code using command line ?
count_if() in C++ STL

In this article we will be discussing the working, syntax and examples of std::count_if() function in C++ STL.
std::count_if() function is an inbuilt function in C++ STL, which is defined in <algorithm> header file. count_if() is used to get the number of elements in a specified range which satisfy a condition. This function returns an integer value which is the number of elements which satisfies the condition.
The function not only iterates through the given range but also checks if the statement or condition is true and counts how many times the statement or condition was true and returns the result.
count_if(start, end, condition);
The function accepts the following parameter(s) −
start, end − These are the iterators which can be used to give a range in which we have to use the function. start gives the beginning position of the range and end gives the ending position of the range.
condition − This is the condition which we want to check. Condition is the unary function which has to be applied on the given range.
This function returns the number of elements which are meeting the condition.
bool iseve(int i){ return ((i%2)==0); }
int a = count_if( vect.begin(), vect.end(), iseve ); /* vect has 10 integers 1-10*/
even numbers = 2 4 6 8 10
 Live Demo
#include <bits/stdc++.h>
using namespace std;
bool check_odd(int i){
   if (i % 2!= 0)
      return true;
   else
      return false;
}
 int main() {
   vector<int> vec;
   for (int i = 0; i < 10; i++){
      vec.push_back(i);
   }
   int total_odd = count_if(vec.begin(), vec.end(), check_odd);
   cout<<"Number of odd is: "<<total_odd;
   return 0;
}
Number of odd is: 5
How can we return a list from a Python function?

There are so many ways we can return a list from a python function. One such function is given below.
def retList():
    list = []
    for i in range(0,10):
        list.append(i)
    return list
a = retList()
print a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
QlikView - Rotating Tables

The Rotating table in QlikView is similar to the column and row transpose feature in
Microsoft Excel but with some additional options. We can transpose columns in multiple directions and they give different results. In this chapter, we will be seeing the normal transpose option of converting rows to columns.
Let us consider the following input data, which represents the actual and forecasted sales figures.
Month,Forecast,Actual
March,2145,2247
April,2458,
May,1245,
June,5124,3652
July,7421,7514
August,2584,
September,5314,4251
October,7846,6354
November,6532,7451
December,4625,1424
January,8547,7852
February,3265,

The above data is loaded to QlikView memory by using the script editor. Open the script editor from the File menu or press Control+E. Choose the "Table Files" option from the "Data from Files" tab and browse for the file containing the above data.
After clicking Next, we choose the Enable Transformation Step button to carry out the required data transformation.
As we are going to use the Rotate function, let us choose the Rotate tab which displays the values of all the fields.
We click the Transpose button to transpose the above data. The transposed data appears as shown below.
The load script for the Transformed data can be seen using the script editor. The script shows the expression, which replaces the empty cell values. 
The transformed data can be seen by creating a Table Box using the option in the menu Layout → New Sheet Object.

    70 Lectures 
     5 hours 

 Arthur Fong
 Print
 Add Notes
 Bookmark this page
Maximum count of pairs which generate the same sum in C++

We are given with an array of integers. The goal is to find the maximum number of pairs in the
array that when added produce the same sum. We have to find the maximum count of such pairs.
Arr[]= { 1,2,3,4,2 }
Maximum count of pairs with same sum : 3
Explanation − Sum of pairs of numbers −
{1,2}, {1,2} Sum:3
{1,3},{2,2} Sum:4
{1,4},{2,3},{3,2} Sum:5
{2,4} Sum:6
{3,4} Sum:7
Maximum count of pairs with same sum is 3 ( for sum = 5 )
Arr[]= { 5,3,6,1 }
Maximum count of pairs with same sum : 1
Explanation − Sum of pairs of numbers −
{5,3} Sum:8
{5,6} Sum:11
{5,1} Sum:6
{3,6} Sum:9
{3,1} Sum:4
{6,1} Sum:7
Maximum count of pairs with the same sum is 1.
The integer array Arr[] is used to store the integers.
The integer array Arr[] is used to store the integers.
Integer ‘size’ stores the length of the array.
Integer ‘size’ stores the length of the array.
Function countEqualSum( int arr[], int n) takes an array , its size as input and returns the
maximum count of pairs which generate the same sum.
Function countEqualSum( int arr[], int n) takes an array , its size as input and returns the
maximum count of pairs which generate the same sum.
First of all we will take ‘sum’ array to store the frequency of unique sums.
First of all we will take ‘sum’ array to store the frequency of unique sums.
At each index of sum, increment count of that element.
At each index of sum, increment count of that element.
Each index of array sum is the sum of a pair of elements.
Each index of array sum is the sum of a pair of elements.
Find maximum such count by search for max element inside array sum and store in maxC.
Find maximum such count by search for max element inside array sum and store in maxC.
Return maxC as result
Return maxC as result
 Live Demo
#include <bits/stdc++.h>
using namespace std;
// Function to return the maximum
// count of pairs with equal sum
int countEqualSum(int arr[], int n){
   int sum[20]={0};
   int maxC = 0;
   // Store counts of sum of all pairs
   for (int i = 0; i < n - 1; i++)
      for (int j = i + 1; j < n; j++){
         sum[ arr[i]+arr[j] ]++;
      }
      for(int i=0;i<20;i++)
         if(sum[i]>maxC)
            maxC=sum[i];
   return maxC;
}
int main(){
   int Arr[] = { 1,2,3,4,2 };
   int size = 5;
   cout <<”Maximum count of pairs which generate the same sum”
   << countEqualSum(Arr, size);
   return 0;
}
Maximum count of pairs which generate the same sum : 3
Can we store CSS color values in MySQL?

Yes, we can. In order to store CSS color value, you can use CHAR(6) without # symbol for hexadecimal. Let us see an example and create a table
mysql> create table storeCSSColorDemo
   -> (
   -> CSSValue char(6)
   -> );
Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command. The records here are individual color values in hexadecimal, for which we have used char(6)
mysql> insert into storeCSSColorDemo values('FF0000');
Query OK, 1 row affected (0.13 sec)
mysql> insert into storeCSSColorDemo values('FFA500');
Query OK, 1 row affected (0.86 sec)
mysql> insert into storeCSSColorDemo values('FFFF00');
Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from storeCSSColorDemo;
The following output displays the color value successfully stored in MySQL table
+----------+
| CSSValue |
+----------+
| FF0000   |
| FFA500   |
| FFFF00   |
+----------+
3 rows in set (0.00 sec)
In the above sample output, the three colors are RED, ORANGE and YELLOW.
NOTE If your column is nullable then you can use VARCHAR(6).
How to create and use a Syntax Highlighter with JavaScript?

To create and use syntax highligher, the code is as follows −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .colorLinks {
      color: rgb(131, 44, 212);
      text-decoration: none;
      font-size: 20px;
      font-weight: bold;
   }
   .setColor {
      margin: 20px;
      padding: 10px;
      border: none;
      font-size: 18px;
      background-color: rgb(226, 43, 89);
      color: white;
   }
</style>
</head>
<body>
<h1>Syntax Highlighting example</h1>
<div class="CodeDiv">
<a href="https://www.google.com">Go to google.com</a>
<a href="https://www.facebook.com">Go to facebook.com</a>
</div>
<button class="setColor" onclick="highlightLinks()">Click Here</button>
<h2>Click the above button to highlight the links</h2>
<script>
   var anchrorRg = /[^<]*(<a href="([^"]+)">([^<]+)<\/a>)/g;
   function highlightLinks() {
      var text = document.querySelector(".CodeDiv").innerHTML;
      text = text.replace(anchrorRg, function() {
         function check(arguments) {
            let tempArr = [];
            tempArr.push(Array.prototype.slice.call(arguments, 2, 4));
            return `<a class="colorLinks" href=${tempArr[0][0]}>${tempArr[0][1]}</a><br>`;
         }
         return check(arguments);
      });
      document.querySelector(".CodeDiv").innerHTML = text;
   }
</script>
</body>
</html>
The above code will produce the following output on window size greater than 700px −
On clicking the “Click Here” button −
Explain the array of structures in C language

An array of structure in C programming is a collection of different datatype variables, grouped together under a single name.
General form of structure declaration
The structural declaration is as follows −
struct tagname{
   datatype member1;
   datatype member2;
   datatype member n;
};
Here, struct is the keyword
    tagname specifies name of structure
    member1, member2 specifies the data items that make up structure.
The following example shows the usage of array of structures in C programming −
struct book{
   int pages;
   char author [30];
   float price;
};
The most common use of structure in C programming is an array of structures.
The most common use of structure in C programming is an array of structures.
To declare an array of structure, first the structure must be defined and then an array variable of that type should be defined.
To declare an array of structure, first the structure must be defined and then an array variable of that type should be defined.
For Example − struct book b[10]; //10 elements in an array of structures of type ‘book’
For Example − struct book b[10]; //10 elements in an array of structures of type ‘book’
The following program shows the usage of array of structures.
 Live Demo
#include <stdio.h>
#include <string.h>
struct student{
   int id;
   char name[30];
   float percentage;
};
int main(){
   int i;
   struct student record[2];
   // 1st student's record
   record[0].id=1;
   strcpy(record[0].name, "Bhanu");
   record[0].percentage = 86.5;
   // 2nd student's record
   record[1].id=2;
   strcpy(record[1].name, "Priya");
   record[1].percentage = 90.5;
   // 3rd student's record
   record[2].id=3;
   strcpy(record[2].name, "Hari");
   record[2].percentage = 81.5;
   for(i=0; i<3; i++){
      printf(" Records of STUDENT : %d \n", i+1);
      printf(" Id is: %d \n", record[i].id);
      printf(" Name is: %s \n", record[i].name);
      printf(" Percentage is: %f\n\n",record[i].percentage);
   }
   return 0;
}
When the above program is executed, it produces the following result −
Records of STUDENT : 1
Id is: 1
Name is: Bhanu
Percentage is: 86.500000
Records of STUDENT : 2
Id is: 2
Name is: Priya
Percentage is: 90.500000
Records of STUDENT : 3
Id is: 3
Name is: Hari
Percentage is: 81.500000
How to find operating system in the client machine using JavaScript?

To detect the operating system on the client machine, your script can analyze the value of navigator.appVersion or navigator.userAgent.
Let us look at detecting the client OS using a simple script −
var operatingSystem = "Unknown OS";
// Check For Windows
if (navigator.appVersion.indexOf("Win") !=- 1) operatingSystem = "Windows";
// Check for Mac
if (navigator.appVersion.indexOf("Mac") !=- 1) operatingSystem = "MacOS";
// Check for UNIX
if (navigator.appVersion.indexOf("X11") !=- 1) operatingSystem = "UNIX";
// Check for Linux
if (navigator.appVersion.indexOf("Linux") !=- 1) operatingSystem = "Linux";
console.log('Your OS: ' + operatingSystem);
If you have a windows system, it'll give the output:
Your OS: Windows
This can also be used to find the browser of the user.
Get first element with maximum value in list of tuples in Python

We have a list of tuple. We are required to find out that tuple which was maximum value in it. But in case more than one tuple has same value we need the first tuple which has maximum value.
With itemgetter(1) we get all the value from index position 1 and then apply a max function to get the item with max value. But in case more than one result is returned, we apply index zero to get the first tuple with maximum element in it.
 Live Demo
from operator import itemgetter
# initializing list
listA = [('Mon', 3), ('Tue', 20), ('Wed', 9)]
# Given list
print("Given list : \n" ,listA)
# using max() and itemgetter()
res = max(listA, key=itemgetter(1))[0]
# printing result
print("Day with maximum score is : \n",res)
Running the above code gives us the following result −
Given list :
[('Mon', 3), ('Tue', 20), ('Wed', 9)]
Day with maximum score is :
Tue
We use the lambda function to get the elements at index position 1 then apply the max function. Then we apply the index position 0 to get the first among multiple matches to get the final result.
 Live Demo
# initializing list
listA = [('Mon', 3), ('Tue', 20), ('Wed', 9)]
# Given list
print("Given list : \n" ,listA)
# using max() and lambda
res = max(listA, key = lambda i : i[1])[0]
# printing result
print("Day with maximum score is : \n",res)
Running the above code gives us the following result −
Given list :
[('Mon', 3), ('Tue', 20), ('Wed', 9)]
Day with maximum score is :
Tue
In this approach we use the sorted function with reversed equal to true condition when applying the lambda function.
 Live Demo
# initializing list
listA = [('Mon', 3), ('Tue', 20), ('Wed', 9)]
# Given list
print("Given list : \n" ,listA)
# using sorted() and lambda
res = sorted(listA, key = lambda i: i[1], reverse = True)[0][0]
# printing result
print("Day with maximum score is : \n",res)
Running the above code gives us the following result −
Given list :
[('Mon', 3), ('Tue', 20), ('Wed', 9)]
Day with maximum score is :
Tue
Java Program to wrap a Primitive DataType in a Wrapper Object

Every Java primitive data type has a class dedicated to it. These classes wrap the primitive data type into an object of that class. Therefore, it is known as wrapper classes.
The following is the program that displays a Primitive DataType in a Wrapper Object.
 Live Demo
public class Demo {
   public static void main(String[] args) {
      Boolean myBoolean = new Boolean(true);
      boolean val1 = myBoolean.booleanValue();
      System.out.println(val1);

      Character myChar = new Character('a');
      char val2 = myChar.charValue();
      System.out.println(val2);

      Short myShort = new Short((short) 654);
      short val3 = myShort.shortValue();
      System.out.println(val3);

      Integer myInt = new Integer(878);
      int val4 = myInt.intValue();
      System.out.println(val4);

      Long myLong = new Long(956L);
      long val5 = myLong.longValue();
      System.out.println(val5);

      Float myFloat = new Float(10.4F);
      float val6 = myFloat.floatValue();
      System.out.println(val6);

      Double myDouble = new Double(12.3D);
      double val7 = myDouble.doubleValue();
      System.out.println(val7);
   }
}
True
a
654
878
956
10.4
12.3
In the above program, we have taken every data type one by one. An example can be seen is for boolean. Our wrapper is −
Boolean myBoolean = new Boolean(true);
Now, the Primitive DataType is wrapped in a Wrapper Object
boolean val1 = myBoolean.booleanValue();