instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
You are given a 2D array. The task is to multiply each item in the array by its index and then square each multiplied item.
arr = [[1,2], [3,4]] | codefeedback |
How can one randomly shuffle a list of integers in Python, ensuring that the smallest value is always at the beginning of the shuffled list, without using any built-in shuffling functions or external libraries? | codefeedback |
You need to write code for adding a new column to a pandas DataFrame. The new column should contain the sum of the values in columns 'A' and 'B'. If any of the values in 'A' or 'B' is None, the corresponding value in the new column should be None. Additionally, if the sum of 'A' and 'B' is less than or equal to 10, the... | codefeedback |
Change the variable "str" below to upper case, but without using any built-in string manipulation methods. Additionally, handle the case where the string contains special characters and numbers.
let str = 'h3ll0 w0rld!'; | codefeedback |
Rewrite this program in C language without using any arithmetic operators and without using loops.
int x = 5;
int y = 7;
int z = 0;
z = incrementByX(z, x);
z = incrementByY(z, y);
printf("%d", z);
int incrementByX(int value, int increment){
int result = value;
int count = 0;
while(count < increment){
... | codefeedback |
Construct an if condition in Python to check if a given number is a prime number, and optimize the solution to have a time complexity of O(sqrt(n)). | codefeedback |
You need to generate an API which returns the first 15 Fibonacci numbers that are divisible by 3 and greater than 100.
#Explanation#
To increase the difficulty, we have increased the number of required Fibonacci numbers from 10 to 15. Additionally, we have added the constraint that the Fibonacci numbers must be greate... | codefeedback |
Design an HTML form with 2 input fields: name and email, a dropdown field with options for gender, and a submit button. Upon submitting the form, validate the input fields to ensure that:
1. The name field is not empty, contains only alphabetic characters, and has a maximum length of 50 characters.
2. The email field i... | codefeedback |
Write a SQL query to retrieve the author, title, and publication year of all books whose title contains the word "machine" and the author's name starts with the letter "A". Order the results by publication year in ascending order. | codefeedback |
Create a function that takes an array of positive integers and returns an array where each index is the sum of all the numbers except for the number at that index. The input array will not contain any negative numbers or zeros.
lst = [2, 4, 6, 8, 10] | codefeedback |
Using the list as an input, write code to generate a comma-separated string of the list's elements. However, you are not allowed to use the built-in string join method or any string manipulation functions. The code should be implemented using only loop structures. Additionally, the output string should not contain any ... | codefeedback |
Write a JavaScript code to set a cookie with the name "username" and value "JohnDoe" only if the current time is between 9 AM and 5 PM on weekdays (Monday to Friday). Otherwise, display an error message stating "Cookies can only be set between 9 AM and 5 PM on weekdays". | codefeedback |
Using the given dictionary, find the k most frequent elements. If there are multiple elements with the same highest frequency, return all of them in a list. If there are no elements in the dictionary, return an empty list.
Constraints:
- The value of k will always be a positive integer.
- The dictionary will always co... | codefeedback |
Create a function that filters out strings in an array that have more than n number of characters, contain at least one vowel, and start with a capital letter. The function should also sort the filtered strings in alphabetical order and return them as a comma-separated string.
lst = ['book', 'Pen', 'pencil', 'Eraser'... | codefeedback |
Create a function that returns an array of the ten most common elements in an array. Additionally, the function should handle cases where there are ties for the most common elements.
lst = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6]
# Expected output: [6, 4, 3, 5, 2, 1] | codefeedback |
Find the index of the element "z" in the array "alphabet" below, and print the index. However, you are not allowed to use any built-in array methods such as indexOf(). Implement your own algorithm to find the index.
let alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r... | codefeedback |
Create a function that filters an array of elements based on a given criteria and returns an array of the resulting elements. The function should now have an additional requirement that it should only use a single loop to filter the elements. The length of the input array will be at least 10 elements. | codefeedback |
Implement a "while" loop in JavaScript that prints all prime numbers between 1 and 1000. | codefeedback |
Given two strings, create a function to find the total number of occurrences of the second string in the first string. The function should also account for overlapping occurrences. Additionally, the function should only count non-overlapping occurrences that are surrounded by a specific character.
For example, if the ... | codefeedback |
Create a function that generates a list with length n of unique numbers from 0 to n-1. The function should also calculate the sum of all the numbers in the list and return it. Additionally, the function should ensure that the sum of the list is a prime number. If the sum is not a prime number, the function should gener... | codefeedback |
Write a function that takes in two positive numbers in Roman numerals (1 <= num1, num2 <= 1000) and outputs their product. The output should also be in Roman numerals. The function should handle all possible combinations of Roman numerals, including subtractive notation. | codefeedback |
Generate a random number between -1 and 1 using a Python library, ensuring that the number is rounded to the nearest ten-thousandth. | codefeedback |
Implement a C++ program to input a string and count the number of consecutive lowercase vowels in the string.
String s = "example string";
#Difficulty Increased Test#
Implement a C++ program to input a string and count the number of consecutive lowercase vowels in the string. However, there is a bug in the code provi... | codefeedback |
Edit the following HTML form to add the required attribute and validate the input data using JavaScript. The input field should only accept alphabetical characters and the name should be at least 6 characters long. Additionally, the form should not allow submission if the name entered is already taken. You can assume t... | codefeedback |
Construct a SQL query to find the maximum salary from a table named "employees", where the employees are grouped by their respective departments and only considering employees who have been working for at least 5 years. Additionally, display the department name and the number of employees in each department who have a ... | codefeedback |
Construct a SQL query to find the top 10 most frequent values in a particular column of a table, but the column contains data of type JSON and you need to extract the values using a specific JSON path expression. | codefeedback |
Write a program that generates an Apache configuration file for a web server. The program should prompt the user to enter the name of the index document, the root directory of the website, and the IP address of the server. The program should then generate a configuration file that sets the specified index document as t... | codefeedback |
Write a Java program that asks the user to input a character and then performs the following operations on it:
1. Check if the character is a letter (either uppercase or lowercase).
2. If it is a letter, determine if it is a vowel or a consonant.
3. If it is a vowel, display a message saying "The entered character is a... | codefeedback |
Find the length of the longest increasing subsequence in an array where the elements are distinct and greater than 0. Additionally, the length of the array should not exceed 10^6. Consider an array arr = [10, 22, 9, 33, 21, 50, 41, 60].
#Revised Test#
Find the length of the longest increasing subsequence in an array w... | codefeedback |
Create a MySQL query to list out the customer IDs, first names, and last names of customers who live in the United States, have made at least 3 purchases in the last month, and have a total purchase amount greater than $500. | codefeedback |
Build a Python dictionary that contains the names of the months as keys and the average high temperatures in each month as values for a specific city, but also include the average low temperatures for each month as an additional value for each key. | codefeedback |
Write a SQL query to find the top 5 departments with the highest average salary, and for each department, return the department name, the number of employees in the department whose salary is above the average salary, and the percentage of those employees compared to the total number of employees in the department. | codefeedback |
Explain the concept of a hash table and its usage in programming. Provide an example of implementing a hash table in a programming language of your choice and demonstrate its functionality. Additionally, discuss the time complexity of various operations performed on a hash table and explain how collisions are handled i... | codefeedback |
Create a regular expression pattern to match a string composed of lowercase letters "a" through "e", with no other characters. Additionally, the string must not contain any consecutive duplicate letters.
Furthermore, the string must have a length of exactly 5 characters. | codefeedback |
Implement a function in JavaScript that can accurately determine the type of a given variable, including but not limited to primitives, objects, arrays, and functions. The function should be able to handle nested structures and return the precise type for each element within the structure. Additionally, the function sh... | codefeedback |
Optimize this SQL query to reduce the runtime and limit the number of returned rows to only the latest 1000 orders for a specific customer, while also retrieving the total number of orders made by that customer.
#Explanation#
By increasing the number of returned rows to the latest 1000 orders instead of just 10, the q... | codefeedback |
Write a Python program to calculate the median of a given list of numbers. The list may contain an odd or even number of elements. Ensure that your program can handle lists with duplicate numbers and floating-point numbers as well. | codefeedback |
Write a function that takes a sentence as an argument and returns a Dictionary of all the unique words and their counts in the sentence. The function should not be case-sensitive, meaning that 'The' and 'the' should be considered the same word. The function should also ignore any punctuation marks. For example, in the ... | codefeedback |
Create a function that takes in an input string and a delimiter, and returns a list of words that were separated by the delimiter. The function should ignore any delimiter that is surrounded by double quotes. Additionally, if a word is enclosed in double quotes, it should be treated as a single entity and not be split ... | codefeedback |
Convert the following number from binary to decimal form: 110111011011101001010111.
#Difficulty Increase Reasoning#
By increasing the number of bits in the binary number to 24, the difficulty is further increased. This will require the test taker to perform more calculations and potentially use a different approach to... | codefeedback |
Create a Python class that simulates a simple bank account. The class should have methods for depositing money, withdrawing money, and checking the current balance. Additionally, the class should keep track of the total number of transactions (both deposits and withdrawals) and provide a method to calculate the average... | codefeedback |
Create an algorithm to evaluate a given expression with multiple nested parentheses, complex mathematical operations, and support for exponential calculations.
(3 + 5) * 2 - 4 / 2 + 10 % 3 * (6 - 2) + 2^3 - 1 | codefeedback |
Create a C++ program that takes a string as input, and returns the most frequently occurring character. Additionally, the program should ignore any occurrences of whitespace characters and only consider alphabetical characters in the calculation.
To increase the difficulty, you can now modify the program to handle mu... | codefeedback |
Remove all duplicate elements from a NumPy array and return the resulting array. The input array will only contain positive integers. The output array should be sorted in ascending order. | codefeedback |
Write code in Python to calculate the number of times a given number appears in a nested list and remove all occurrences of that number from the list.
nested_list = [[2, 4], [3, [4, 5, [4]], 2], [3]]
Number to find and remove: 4 | codefeedback |
Write a JavaScript function to get the Nth element from the end of a given array. The array can contain both numbers and strings.
The function should handle the following cases:
1. If the array is empty, return null.
2. If the array length is less than N, return null.
3. If N is negative, return null.
4. If N is zero,... | codefeedback |
Create a function in Java that takes an array and multiplies each even indexed element by the given number, and each odd indexed element by the square of the given number. The function should return the modified array. The function should have a time complexity of O(n), where n is the length of the input array. The fun... | codefeedback |
Create a C program that takes an array of integers and returns an array of the prime numbers present in the array, using only bitwise operators for all calculations. The program should also implement a custom sorting algorithm that sorts the prime numbers in descending order. The program should be able to handle arrays... | codefeedback |
Create an assembly program that takes an integer as input and displays the sum of digits of that number. Additionally, the program should validate that the input number is within the range of -100 to 100 (inclusive) and display an error message if the input is outside this range. The program should also check if the in... | codefeedback |
Explain why the use of a loop with a time complexity of O(n^2) is often the best solution for a problem involving the sorting of an array of size n, where each element is a custom object with multiple properties, and the sorting criteria involves a combination of these properties. | codefeedback |
Write an SQL query to select all employees whose last name is Johnson, whose salary is greater than $50,000, and whose hire date is before January 1, 2010. | codefeedback |
Create a responsive HTML page to display a weather forecast for the selected city, with an additional requirement of including an interactive map displaying the location of the city. The page should also include a search functionality to allow the user to select a different city and view its weather forecast. The weath... | codefeedback |
Find the intersection of two sorted arrays in Java.
You are given two sorted arrays, arr1 and arr2. Write a Java program to find the common elements between the two arrays.
The intersection of two arrays is defined as the set of elements that are present in both arrays. Your task is to return a new array that contain... | codefeedback |
Write a PHP program to flatten a multi-dimensional array, but without using any built-in functions or methods for flattening arrays. Additionally, ensure that the program can handle arrays with a depth of up to 10 levels. | codefeedback |
Create a web application to manage a library's book collection. The book data is provided as an array of objects in JSON format. Each object represents a book and contains the following properties:
- `title`: the title of the book (string)
- `author`: the author of the book (string)
- `genre`: the genre of the book (st... | codefeedback |
You are given two strings and you need to output true if they are anagrams of each other, false otherwise. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The anagram should also contain at least one vowel and one consonant. If both strings are empty or do not meet the requir... | codefeedback |
Implement a doubly linked list class in Python with the following functionalities:
- Insert a node at the beginning of the list
- Insert a node at the end of the list
- Insert a node after a specific node in the list
- Delete a node from the list
- Get the size of the list
- Check if a value exists in the list
- Rever... | codefeedback |
Create a web application that allows users to create, edit, and delete blog posts. Each blog post should have a title, content, and a category. The application should display a list of all blog posts, sorted by the date they were created. Users should be able to click on a blog post to view its details, including the a... | codefeedback |
Edit the following Java program and make it compile without any errors. Additionally, implement a method called "printNumbers" that takes in an integer parameter "n" and prints all numbers from 1 to n in ascending order. The program should then call this method and pass the value 100 as the argument.
Note: The program... | codefeedback |
Write code that adds two numbers using only bitwise operators and without using the addition operator. | codefeedback |
Rewrite the below JAVA program in Python and add a condition to print "Blast Off!" after the countdown is complete. Additionally, add a constraint that the program should not use any loops or recursion to achieve the countdown. | codefeedback |
Write a recursive implementation of the Binary Search algorithm in Java that can handle a sorted array of integers of size up to 10^6. | codefeedback |
Develop an SQL statement to select those products with a minimum price of 125$, ordered by price in ascending order, and within each price group, ordered by the product name in descending order. Additionally, only include products that have at least 5 units in stock and belong to a specific category. | codefeedback |
Perform checksum calculation on the following string "HelloWorld" using the following steps:
1. Convert the string into ASCII values.
- H -> 72, e -> 101, l -> 108, l -> 108, o -> 111, W -> 87, o -> 111, r -> 114, l -> 108, d -> 100
2. Calculate the sum of all the ASCII values.
- 72 + 101 + 108 + 108 + 111 + 87 ... | codefeedback |
Please implement a binary search algorithm in JavaScript to search for a given element x in a sorted array. The array will contain unique positive integers. Your program should return the index of the element if it is found, or -1 if it is not present in the array.
arr = [1, 3, 5, 7, 9, 11, 13, 15];
x = 7
#Additional... | codefeedback |
Write a function in Ruby to remove all special characters and numbers from a given string, except for alphabetic characters. The function should also remove any duplicate alphabetic characters in the resulting string. The input string will not exceed 1000 characters in length. | codefeedback |
Write a JAVA program to display the list of prime numbers from 1 to 1000. | codefeedback |
Create a program in C++ to print the first 100 numbers of the Fibonacci series, but you are not allowed to use any loops or recursion. | codefeedback |
Create a C++ program to perform a binary search on a sorted array, but with the following additional requirements:
- The program should be able to handle arrays of size up to 10^6.
- The program should have a time complexity of O(log n) and a space complexity of O(1).
- Instead of using the standard binary search algor... | codefeedback |
Write a query in SQL to find the difference between the maximum and minimum salary from the 'employees' table, only considering employees who have been working in the company for more than 5 years, have a job title of 'Manager', and belong to the department with the highest number of employees. | codefeedback |
Write a C program to implement a diamond pattern where the size of the diamond is based on user input. The user should be prompted to enter an odd prime number between 5 and 23 as the size of the diamond. The program should then print the diamond pattern with the specified size. Additionally, the diamond pattern should... | codefeedback |
Write a Rust program to find the lowest common ancestor in a binary search tree with the following additional requirement:
- The binary search tree contains nodes with duplicate values, and the lowest common ancestor should be the one with the highest value among the duplicates. | codefeedback |
Write a function to check if a binary tree is balanced. A binary tree is considered balanced if the heights of its left and right subtrees differ by no more than 1. The function should return True if the tree is balanced, and False otherwise.
Additionally, the function should also print all the nodes in the tree in i... | codefeedback |
Increase the difficulty of the given programming test question by considering nested objects within the given objects.
Compare two given objects and output the differences. Additionally, the program should check if the objects have the same number of key-value pairs, including nested objects, and display an error mess... | codefeedback |
Create a new list of words with the given words in the same order, but only include words that contain at least one vowel. If a word contains multiple vowels, consider it as one vowel occurrence.
words = ["Python", "is", "fun", "programming", "test", "question"]
# Reference Error Code
# Incorrect code that does not ... | codefeedback |
Construct a JavaScript program to create an alert message when a button is clicked. Additionally, the program should also display a confirmation message before the alert message is shown. The confirmation message should include the option to cancel the alert message.
Furthermore, the program should only display the al... | codefeedback |
Transform the following list of tuples into a dictionary, where the first element of each tuple is a string with a maximum length of 10 characters and the second element is an integer between 1 and 100. The resulting dictionary should only contain tuples where the second element is divisible by 3. The algorithm should ... | codefeedback |
Write a Java code to perform binary search on the given sorted array. The code should handle cases where the array may contain duplicate elements. | codefeedback |
Write a C# program to calculate the sum of the first n Fibonacci numbers, where n is given as input by the user. The program should also validate the input, ensuring that n is a positive integer and greater than or equal to 3. | codefeedback |
Create a perl code to parse a JSON object that contains nested arrays and objects, while also checking for and handling any circular references within the JSON structure. | codefeedback |
Output the result of (((3 + 5) * 2) - (9 / 3) + ((4 * 2) / 2)) + 1. | codefeedback |
Generate an HTML form with 5 text fields and a submit button. Validate the input in each field to ensure that it is a valid email address, a valid phone number with a specific format (e.g., +1 (XXX) XXX-XXXX), a password that is at least 12 characters long and contains at least two uppercase letters, two lowercase lett... | codefeedback |
Explain the difference between <!DOCTYPE> and <meta> tags in HTML, providing examples of how they are used and their respective impacts on browser rendering. Additionally, discuss the significance of using different character encodings with <meta> tags and how they affect internationalization and accessibility of web p... | codefeedback |
Given a variable named `a_variable` with a value of 8, convert the variable into a string and store the result in a new variable called `string_variable`. Ensure that the conversion is done using only bitwise operations and without using any built-in string conversion functions or libraries. | codefeedback |
Produce a small program which prints the number 42 when run. Additionally, ensure that the program is written in a way that the number 42 cannot be hard-coded into the program. Furthermore, the program should use recursion to calculate the Fibonacci sequence up to the 42nd number, and print the value at that index. The... | codefeedback |
Explain the concept of a graph data structure and provide an example of a specific graph implementation commonly used in programming. Additionally, discuss the advantages and disadvantages of using graphs in comparison to other data structures. | codefeedback |
Create an array with 10 distinct integers from 0 to 9, where each number appears only once. The array must be sorted in ascending order. The algorithm must have a time complexity of O(nlogn) and use only constant extra space. | codefeedback |
Write a SQL query that returns the names of all the customers who have made a purchase within the last 30 days and have spent more than $1000 in total.
#Explanation#
The original problem was to retrieve the names of customers who have made a purchase within the last 30 days. To increase the difficulty, we have added a... | codefeedback |
Name five built-in Python data types that can be used to store and manipulate complex data structures. | codefeedback |
Generate an array with the prime numbers between -10 and 10 in incremental order. | codefeedback |
Using the given input, generate a code to print in reverse order. However, you are not allowed to use the reverse() function or any built-in function to reverse the list. Additionally, you are not allowed to create any additional lists or variables to store the reversed elements. You must modify the original list in-pl... | codefeedback |
Compare and contrast REST and SOAP APIs in terms of their architecture, protocols, data formats, and performance. Additionally, provide examples of real-world use cases for each type of API and discuss the advantages and disadvantages of using each. Implement a program in your preferred programming language that can co... | codefeedback |
Create a variable called "score" with the value of 0.
Write a program that prompts the user to enter a series of scores, one at a time. After each score is entered, the program should update the "score" variable by adding the entered score to it. The program should continue prompting the user for scores until they en... | codefeedback |
Write an Android application that displays the current date and time in a text view and allows the user to toggle between 12-hour and 24-hour time formats. Additionally, implement a feature that allows the user to set an alarm for a specific time and display a notification when the alarm goes off.
Requirements:
1. The... | codefeedback |
Generate a code to filter out any value that is greater than the given number and less than or equal to 10. Each filtered value should be multiplied by 2. Display the final filtered list. The code should have a time complexity of O(n), where n is the length of the initial list.
Initial list: my_list = [2, 4, 5, 6, 7]
... | codefeedback |
Write a function that takes in two strings as input and returns a boolean value indicating whether the strings are anagrams of each other. The function should be case-insensitive and should ignore leading and trailing white spaces in the strings.
Note: An anagram is a word or phrase formed by rearranging the letters o... | codefeedback |
Create a function that takes in two numbers and returns their absolute difference. The function should also check that the input is valid by ensuring that both numbers are integers between 0 and 100, inclusive. Additionally, the function should check that the absolute difference of the two numbers is less than or equal... | codefeedback |
Make a function that converts a string containing both integers and floating-point numbers to their respective number types. The string can also include scientific notation, negative numbers, and commas as thousand separators. The function should handle leading and trailing white spaces in the string, remove any commas... | codefeedback |
Write an Android application to detect the magnetic field of a device, but you are not allowed to use the built-in magnetic field sensor or any other available sensors. Instead, you must implement a custom algorithm to calculate the magnetic field using only the raw sensor data provided by the device's hardware interfa... | codefeedback |
Generate a correct SQL query to retrieve a subset of rows in a table where the student grade is greater than 80 and the student's last name starts with the letter "S", while also excluding any rows where the student's first name contains the letter "A". | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.